Module: Helpers
- Defined in:
- lib/helpers.rb
Class Method Summary collapse
Class Method Details
.array_to_hash(array) ⇒ Object
18 19 20 21 22 |
# File 'lib/helpers.rb', line 18 def self.array_to_hash(array) hash = {} array.each_with_index { |val, i| hash[i.to_s] = val } hash end |
.normalize_yaml(yaml) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/helpers.rb', line 3 def self.normalize_yaml(yaml) return '' if yaml.nil? return yaml if yaml.is_a? String return yaml.to_s if yaml.is_a? Numeric return yaml.to_s if !!yaml == yaml # if boolean return ":#{yaml.to_s}" if yaml.is_a? Symbol yaml = array_to_hash(yaml) if yaml.is_a? Array normalized = {} yaml.each do |key, value| normalized[key.to_s] = normalize_yaml(value) end normalized end |
.pluralization?(object) ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/helpers.rb', line 24 def self.pluralization?(object) return false if object.nil? keys = object.keys.map { |k| k.to_sym } (keys.include? :one) and (keys.include? :other) end |