epitools 0.5.9 → 0.5.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -7
- data/VERSION +1 -1
- data/epitools.gemspec +3 -3
- data/lib/epitools.rb +1 -1
- data/lib/epitools/numwords.rb +2 -0
- data/lib/epitools/typed_struct.rb +43 -11
- data/lib/epitools/wm.rb +1 -1
- data/spec/numwords_spec.rb +4 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -8,17 +8,17 @@ Enhanced base classes: {Enumerable}[http://rdoc.info/github/epitron/epitools/mas
|
|
8
8
|
|
9
9
|
Extras:
|
10
10
|
|
11
|
-
* {Colored}[http://rdoc.info/github/epitron/epitools/master/Colored] (enhanced version of defunkt's colored -- adds ANSI colouring methods to String, eg: #red, #green, #light_blue, etc.)
|
12
11
|
* {Path}[http://rdoc.info/github/epitron/epitools/master/Path] (a better Pathname)
|
13
|
-
* {Rash}[http://rdoc.info/github/epitron/epitools/master/Rash] (a hash which can have Regexps as keys, so that many input keys can map to a single value.)
|
14
|
-
* {Progressbar}[http://rdoc.info/github/epitron/epitools/master/Progressbar] (better than the progressbar gem)
|
15
|
-
* {Browser}[http://rdoc.info/github/epitron/epitools/master/Browser] (a fake browser, using mechanize, Progressbar, and CacheDB)
|
16
|
-
* {WM}[http://rdoc.info/github/epitron/epitools/master/WM] (control/query desktop windows in X. Note: `wmctrl` must be installed)
|
17
12
|
* {TypedStruct}[http://rdoc.info/github/epitron/epitools/master/TypedStruct] (like Struct, but setters always coerce input to a certain type, eg: boolean, integer, etc.)
|
18
|
-
* {
|
13
|
+
* {WM}[http://rdoc.info/github/epitron/epitools/master/WM] (control/query desktop windows in X. Note: `wmctrl` must be installed)
|
14
|
+
* {Sys}[http://rdoc.info/github/epitron/epitools/master/Sys] (system tools -- determine operating system, list processes, view network statistics, etc.)
|
15
|
+
* {Colored}[http://rdoc.info/github/epitron/epitools/master/Colored] (enhanced version of defunkt's colored -- adds ANSI colouring methods to String, eg: #red, #green, #light_blue, etc.)
|
19
16
|
* {Term}[http://rdoc.info/github/epitron/epitools/master/Term] (a toolbox for making terminal-based scripts -- get terminal size, create tables, etc.)
|
20
17
|
* {Iter}[http://rdoc.info/github/epitron/epitools/master/Iter] (a "stable iterator" -- lets you write algorithms that modify the array as you're iterating; good for clustering.)
|
21
|
-
* {
|
18
|
+
* {Browser}[http://rdoc.info/github/epitron/epitools/master/Browser] (a fake browser, with a cache, cookies, download progress bars, plus the rest of the mechanize/nokogiri API you know and love)
|
19
|
+
* {Rash}[http://rdoc.info/github/epitron/epitools/master/Rash] (a hash which can have Regexps as keys, so that many input keys can map to a single value.)
|
20
|
+
* {Progressbar}[http://rdoc.info/github/epitron/epitools/master/Progressbar] (better than the progressbar gem)
|
21
|
+
* {MimeMagic}[http://rdoc.info/github/epitron/epitools/master/MimeMagic] (a port of the Unix `file` utility for automatically recognizing files based on their contents; faster than running `file` on every file if you have to process large batches of files)
|
22
22
|
|
23
23
|
== Installing
|
24
24
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.10
|
data/epitools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "epitools"
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["epitron"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-08-26"
|
13
13
|
s.description = "Miscellaneous utility libraries to make my life easier."
|
14
14
|
s.email = "chris@ill-logic.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -89,7 +89,7 @@ Gem::Specification.new do |s|
|
|
89
89
|
s.homepage = "http://github.com/epitron/epitools"
|
90
90
|
s.licenses = ["WTFPL"]
|
91
91
|
s.require_paths = ["lib"]
|
92
|
-
s.rubygems_version = "1.8.
|
92
|
+
s.rubygems_version = "1.8.23"
|
93
93
|
s.summary = "NOT UTILS... METILS!"
|
94
94
|
|
95
95
|
if s.respond_to? :specification_version then
|
data/lib/epitools.rb
CHANGED
data/lib/epitools/numwords.rb
CHANGED
@@ -1,31 +1,56 @@
|
|
1
1
|
#
|
2
|
-
# Like a Stuct, but automatically casts
|
2
|
+
# Like a Stuct, but automatically casts assignments to specific types.
|
3
3
|
#
|
4
4
|
# Example:
|
5
5
|
#
|
6
|
-
# class SomeRecord < TypedStruct["some_id:int amount:float
|
7
|
-
#
|
6
|
+
# class SomeRecord < TypedStruct["some_id:int amount:float name:string a,b,c:bool untyped_var"]
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# record = SomeRecord.new(69, 12348.871, "stringy", true, 1, "no", Object.new)
|
10
|
+
#
|
11
|
+
# another_record = SomeRecord.new :amount=>"1.5", :name=>"Steve", :c=>"true", :a=>"disable", :untyped_var=>Ratio.new(1/2)
|
12
|
+
# record.amount *= 3.141592653589793238462643383279
|
13
|
+
#
|
14
|
+
# Recognized types, and what they get converted into:
|
15
|
+
#
|
16
|
+
# <no type given> => Don't enforce a type -- any ruby object is allowed.
|
17
|
+
# ["str", "string"] => String
|
18
|
+
# ["int", "integer"] => Integer
|
19
|
+
# ["float"] => Float
|
20
|
+
# ["bigdecimal"] => BigDecimal
|
21
|
+
# ["hex"] => Integer
|
22
|
+
# ["date", "time", "datetime"] => DateTime (using DateTime.parse)
|
23
|
+
# ["timestamp", "unixtime"] => Time (using Time.at)
|
24
|
+
# ["bool", "boolean"] => Boolean, using the following rules:
|
25
|
+
# false when: false, nil, 0, "0", "off", "no",
|
26
|
+
# "false", "disabled", "disable"
|
27
|
+
# true when: true, 1, "1", "on", "yes",
|
28
|
+
# "true", "enabled", "enable"
|
8
29
|
#
|
9
30
|
class TypedStruct < Struct
|
10
31
|
|
11
32
|
## TODO: Compact syntax: "a,b,c:int x:string y:date"
|
12
33
|
## TODO: Optional commas separating fields: "a, b, c:int, d:bool"
|
13
34
|
## TODO: booleans fields add "field?" methods
|
35
|
+
## TODO: default values: "a:int(default=50)" or "b:int(50)"
|
14
36
|
|
15
37
|
#
|
16
38
|
# A perhaps-too-clever table of { "typename" => convert_proc } mappings.
|
17
39
|
#
|
18
40
|
CONVERTERS = Hash[ *{
|
19
|
-
[
|
41
|
+
[:passthru] => :passthru,
|
42
|
+
["str", "string"] => proc { |me| me.to_s },
|
20
43
|
["int", "integer"] => proc { |me| me.to_i },
|
44
|
+
["float"] => proc { |me| me.to_f },
|
45
|
+
["bigdecimal"] => proc { |me| BigDecimal.new me },
|
21
46
|
["hex"] => proc { |me| me.to_i(16) },
|
22
47
|
["date", "time", "datetime"] => proc { |me| DateTime.parse me },
|
23
|
-
["timestamp"]
|
48
|
+
["timestamp", "unixtime"] => proc { |me| Time.at me },
|
24
49
|
["bool", "boolean"] => proc do |me|
|
25
50
|
case me
|
26
|
-
when false, 0, "0", "off", "no", "false",
|
51
|
+
when false, nil, 0, "0", "off", "no", "false", "disabled", "disable"
|
27
52
|
false
|
28
|
-
when true, 1, "1", "on", "yes", "true"
|
53
|
+
when true, 1, "1", "on", "yes", "true", "enabled", "enable"
|
29
54
|
true
|
30
55
|
else
|
31
56
|
raise "Invalid boolean type: #{me.inspect}"
|
@@ -41,7 +66,8 @@ class TypedStruct < Struct
|
|
41
66
|
pairs = specs.split.map do |spec|
|
42
67
|
name, type = spec.split(":")
|
43
68
|
|
44
|
-
type ||=
|
69
|
+
type ||= :passthru
|
70
|
+
|
45
71
|
unless converter = CONVERTERS[type]
|
46
72
|
raise "Unknown type: #{type}"
|
47
73
|
end
|
@@ -49,7 +75,7 @@ class TypedStruct < Struct
|
|
49
75
|
[name.to_sym, converter]
|
50
76
|
end
|
51
77
|
|
52
|
-
# initialize the
|
78
|
+
# initialize the Struct
|
53
79
|
struct = new(*pairs.transpose.first)
|
54
80
|
|
55
81
|
# overload setter methods to call the proc
|
@@ -63,8 +89,14 @@ class TypedStruct < Struct
|
|
63
89
|
struct
|
64
90
|
end
|
65
91
|
|
66
|
-
def initialize(*args)
|
67
|
-
|
92
|
+
def initialize(*args)
|
93
|
+
if args.size == 1 and args.first.is_a? Hash
|
94
|
+
opts = args.first
|
95
|
+
else
|
96
|
+
opts = Hash[members.zip(args)]
|
97
|
+
end
|
98
|
+
|
99
|
+
opts.each { |key,value| send "#{key}=", value }
|
68
100
|
end
|
69
101
|
|
70
102
|
end
|
data/lib/epitools/wm.rb
CHANGED
data/spec/numwords_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
version: '0'
|
157
157
|
requirements: []
|
158
158
|
rubyforge_project:
|
159
|
-
rubygems_version: 1.8.
|
159
|
+
rubygems_version: 1.8.23
|
160
160
|
signing_key:
|
161
161
|
specification_version: 3
|
162
162
|
summary: NOT UTILS... METILS!
|