Class: Iyzi::Utils
- Inherits:
-
Object
- Object
- Iyzi::Utils
- Defined in:
- lib/iyzi/utils.rb
Class Method Summary collapse
- .convert_to_hash(v) ⇒ Object
- .convert_to_prop(v) ⇒ Object
- .hash_to_properties(hash) ⇒ Object
- .properties_to_hash(props) ⇒ Object
Class Method Details
.convert_to_hash(v) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/iyzi/utils.rb', line 26 def convert_to_hash(v) if v.is_a?(Hash) properties_to_hash(v) elsif v.is_a?(Array) v.collect { |item| properties_to_hash(item) } else v end end |
.convert_to_prop(v) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/iyzi/utils.rb', line 16 def convert_to_prop(v) if v.is_a?(Hash) hash_to_properties(v) elsif v.is_a?(Array) v.collect { |item| hash_to_properties(item) } else v end end |
.hash_to_properties(hash) ⇒ Object
4 5 6 7 8 |
# File 'lib/iyzi/utils.rb', line 4 def hash_to_properties(hash) newprops = {} hash.each_pair { |k, v| newprops[k.to_s.camelize(:lower)] = convert_to_prop(v) } newprops end |
.properties_to_hash(props) ⇒ Object
10 11 12 13 14 |
# File 'lib/iyzi/utils.rb', line 10 def properties_to_hash(props) hash = HashWithIndifferentAccess.new props.each_pair { |k, v| hash[k.underscore] = convert_to_hash(v) } hash end |