epitools 0.5.9 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
- * {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)
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
- * {Sys}[http://rdoc.info/github/epitron/epitools/master/Sys] (system tools -- determine operating system, list processes, view network statistics, etc.)
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.9
1
+ 0.5.10
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "epitools"
8
- s.version = "0.5.9"
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-07-09"
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.24"
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
@@ -12,7 +12,7 @@ require_wrapper = proc do |mod|
12
12
  end
13
13
 
14
14
  #
15
- # Make all the modules autoload, and require all the monkeypatches
15
+ # Load the things that can't be autoloaded
16
16
  #
17
17
  %w[
18
18
  core_ext
@@ -53,6 +53,8 @@ class Numeric
53
53
  num_triplets = triplets.size
54
54
 
55
55
  triplets.each_with_index do |triplet, i|
56
+ next if triplet.to_i == 0
57
+
56
58
  result = []
57
59
 
58
60
  tens, hunds = nil, nil
@@ -1,31 +1,56 @@
1
1
  #
2
- # Like a Stuct, but automatically casts input to specific types.
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 x:string a,b,c:bool"]; end
7
- # record = SomeRecord.new(69, 12348.871, "stringy", true, 1, "no")
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
- ["str", "string"] => :passthru,
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"] => proc { |me| Time.at me },
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", nil
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 ||= "string"
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 C Struct
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
- members.zip(args).each { |field,value| send "#{field}=", value }
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
@@ -92,7 +92,7 @@ module WM
92
92
  end
93
93
 
94
94
  def command
95
- process.command
95
+ process && process.command
96
96
  end
97
97
 
98
98
  def inspect
@@ -31,5 +31,9 @@ describe Numeric do
31
31
  it "handles 1.thousand.to_words properly" do
32
32
  1.thousand.to_words.should == "one thousand"
33
33
  end
34
+
35
+ it "handles 1.quadrillion.to_words properly" do
36
+ 1.quadrillion.to_words.should == "one quadrillion"
37
+ end
34
38
 
35
39
  end
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.9
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-07-09 00:00:00.000000000 Z
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.24
159
+ rubygems_version: 1.8.23
160
160
  signing_key:
161
161
  specification_version: 3
162
162
  summary: NOT UTILS... METILS!