Class: Jerakia::Answer
- Inherits:
-
Object
- Object
- Jerakia::Answer
- Defined in:
- lib/jerakia/answer.rb
Instance Attribute Summary collapse
-
#datatype ⇒ Object
Returns the value of attribute datatype.
-
#lookup_type ⇒ Object
readonly
Returns the value of attribute lookup_type.
-
#payload ⇒ Object
Returns the value of attribute payload.
Instance Method Summary collapse
- #flatten_payload! ⇒ Object
-
#initialize(lookup_type = :first) ⇒ Answer
constructor
A new instance of Answer.
-
#merge_payload!(method = :hash) ⇒ Object
TODO: consolidate this into less lines.
- #set_data_type ⇒ Object
Constructor Details
#initialize(lookup_type = :first) ⇒ Answer
Returns a new instance of Answer.
9 10 11 12 13 14 15 16 17 |
# File 'lib/jerakia/answer.rb', line 9 def initialize(lookup_type = :first) case lookup_type when :first @payload = nil when :cascade @payload = [] @datatype = 'array' end end |
Instance Attribute Details
#datatype ⇒ Object
Returns the value of attribute datatype.
6 7 8 |
# File 'lib/jerakia/answer.rb', line 6 def datatype @datatype end |
#lookup_type ⇒ Object (readonly)
Returns the value of attribute lookup_type.
7 8 9 |
# File 'lib/jerakia/answer.rb', line 7 def lookup_type @lookup_type end |
#payload ⇒ Object
Returns the value of attribute payload.
5 6 7 |
# File 'lib/jerakia/answer.rb', line 5 def payload @payload end |
Instance Method Details
#flatten_payload! ⇒ Object
19 20 21 |
# File 'lib/jerakia/answer.rb', line 19 def flatten_payload! @payload.flatten! end |
#merge_payload!(method = :hash) ⇒ Object
TODO: consolidate this into less lines
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jerakia/answer.rb', line 25 def merge_payload!(method = :hash) # rubocop:disable Metrics/MethodLength payload_hash = {} @payload.each do |p| next unless p.is_a?(Hash) case method when :hash payload_hash = p.merge(payload_hash) when :deep_hash payload_hash = p.deep_merge!(payload_hash) end end @payload = payload_hash set_data_type end |
#set_data_type ⇒ Object
40 41 42 |
# File 'lib/jerakia/answer.rb', line 40 def set_data_type @data_type = @payload.class.to_s.downcase end |