Class: Edi::Google::Sender::ProductInputHandler
- Inherits:
-
Oj::ScHandler
- Object
- Oj::ScHandler
- Edi::Google::Sender::ProductInputHandler
- Defined in:
- app/services/edi/google/sender.rb
Overview
Builds one product hash at a time from the staged JSON array. The root
array is a sentinel rather than a Ruby Array, so parsed products become
unreachable immediately after the Merchant API call.
Constant Summary collapse
- ROOT =
Object.new.freeze
Instance Method Summary collapse
- #array_append(array, value) ⇒ Object
- #array_end ⇒ Object
- #array_start ⇒ Object
- #hash_set(hash, key, value) ⇒ Object
- #hash_start ⇒ Object
-
#initialize(&consumer) ⇒ ProductInputHandler
constructor
A new instance of ProductInputHandler.
Constructor Details
#initialize(&consumer) ⇒ ProductInputHandler
Returns a new instance of ProductInputHandler.
28 29 30 31 |
# File 'app/services/edi/google/sender.rb', line 28 def initialize(&consumer) @consumer = consumer @array_depth = 0 end |
Instance Method Details
#array_append(array, value) ⇒ Object
41 42 43 |
# File 'app/services/edi/google/sender.rb', line 41 def array_append(array, value) array.equal?(ROOT) ? @consumer.call(value) : array << value end |
#array_end ⇒ Object
45 46 47 |
# File 'app/services/edi/google/sender.rb', line 45 def array_end @array_depth -= 1 end |
#array_start ⇒ Object
36 37 38 39 |
# File 'app/services/edi/google/sender.rb', line 36 def array_start @array_depth += 1 @array_depth == 1 ? ROOT : [] end |
#hash_set(hash, key, value) ⇒ Object
34 |
# File 'app/services/edi/google/sender.rb', line 34 def hash_set(hash, key, value) = hash[key] = value |
#hash_start ⇒ Object
33 |
# File 'app/services/edi/google/sender.rb', line 33 def hash_start = {} |