Module: RbInvoice::Util
- Defined in:
- lib/rbinvoice/util.rb
Class Method Summary collapse
- .read_with_yaml(text) ⇒ Object
- .stringify_array(arr) ⇒ Object
- .stringify_hash(h) ⇒ Object
- .symbolize_array(arr) ⇒ Object
- .symbolize_hash(h) ⇒ Object
Class Method Details
.read_with_yaml(text) ⇒ Object
24 25 26 |
# File 'lib/rbinvoice/util.rb', line 24 def self.read_with_yaml(text) symbolize_hash(YAML::load(text) || {}) end |
.stringify_array(arr) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/rbinvoice/util.rb', line 28 def self.stringify_array(arr) arr.map{|x| case x when Hash; stringify_hash(x) when Array; stringify_array(x) else x end } end |
.stringify_hash(h) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/rbinvoice/util.rb', line 38 def self.stringify_hash(h) h.each_with_object({}) {|(k,v), h| h[k.to_s] = case v when Hash; stringify_hash(v) when Array; stringify_array(v) else; v end } end |
.symbolize_array(arr) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/rbinvoice/util.rb', line 4 def self.symbolize_array(arr) arr.map{|x| case x when Hash; symbolize_hash(x) when Array; symbolize_array(x) else x end } end |
.symbolize_hash(h) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/rbinvoice/util.rb', line 14 def self.symbolize_hash(h) h.each_with_object({}) {|(k,v), h| h[k.to_sym] = case v when Hash; symbolize_hash(v) when Array; symbolize_array(v) else; v end } end |