Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/labrat/hash.rb

Instance Method Summary collapse

Instance Method Details

#optionizeObject

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
  options = []
  each_pair do |k, v|
    key = k.to_s.tr('_', '-')
    options <<
      if [TrueClass, FalseClass].include?(v.class)
        v ? "--#{key}" : "--no-#{key}"
      else
        "--#{key}=#{v}"
      end
  end
  options
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