Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/labrat/hash.rb
Instance Method Summary collapse
-
#optionize ⇒ Object
Convert the given Hash into a Array of Strings that represent an equivalent set of command-line args and pass them into the #parse method.
- #report(title) ⇒ Object
Instance Method Details
#optionize ⇒ Object
Convert the given Hash into a Array of Strings that represent an equivalent set of command-line args and pass them into the #parse method.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/labrat/hash.rb', line 6 def optionize = [] each_pair do |k, v| key = k.to_s.tr('_', '-') << if [TrueClass, FalseClass].include?(v.class) v ? "--#{key}" : "--no-#{key}" else "--#{key}=#{v}" end end end |
#report(title) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/labrat/hash.rb', line 20 def report(title) warn "#{title}:" if empty? warn " [[Empty]]" else each do |k, v| val = v.class == Float ? v.round(2).to_s + 'pt' : v warn " #{k}: #{val}" end end warn "" end |