Module: Connect::Conversions
- Included in:
- Entry::Value, ObjectDefinition
- Defined in:
- lib/connect/conversions.rb
Instance Method Summary collapse
- #convert_array(array) ⇒ Object
- #convert_array_entry(v) ⇒ Object
- #convert_hash(hash) ⇒ Object
- #convert_hash_entry(k, v) ⇒ Object
Instance Method Details
#convert_array(array) ⇒ Object
12 13 14 |
# File 'lib/connect/conversions.rb', line 12 def convert_array(array) Connect::ExtendedArray.new(array.map { |e| convert_array_entry(e)}) end |
#convert_array_entry(v) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/connect/conversions.rb', line 35 def convert_array_entry(v) case v when Hash convert_hash(v) when Array convert_array(v) else v.respond_to?(:final) ? v.final : v end end |
#convert_hash(hash) ⇒ Object
8 9 10 |
# File 'lib/connect/conversions.rb', line 8 def convert_hash(hash) MethodHash[hash.map { |k, v| convert_hash_entry(k, v) }] end |
#convert_hash_entry(k, v) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/connect/conversions.rb', line 16 def convert_hash_entry(k, v) case v when Connect::Entry::ObjectReference # TODO: Refacter. This is to difficult if v.object_id == k key, value = v.final.to_a[0] [key, value] else v.respond_to?(:final) ? [k, v.final] : [k, v] end when Hash [k, convert_hash(v)] when Array [k, convert_array(v)] else v.respond_to?(:final) ? [k, v.final] : [k, v] end end |