Class: Batch
- Inherits:
-
Object
- Object
- Batch
- Includes:
- Enumerable
- Defined in:
- lib/smartystreets_ruby_sdk/batch.rb
Constant Summary collapse
- MAX_BATCH_SIZE =
100
Instance Attribute Summary collapse
-
#all_lookups ⇒ Object
readonly
Returns the value of attribute all_lookups.
-
#named_lookups ⇒ Object
readonly
Returns the value of attribute named_lookups.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #add(lookup) ⇒ Object
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #get_by_index(index) ⇒ Object
- #get_by_input_id(input_id) ⇒ Object
-
#initialize ⇒ Batch
constructor
A new instance of Batch.
- #is_full ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ Batch
Returns a new instance of Batch.
7 8 9 10 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 7 def initialize @named_lookups = {} @all_lookups = [] end |
Instance Attribute Details
#all_lookups ⇒ Object (readonly)
Returns the value of attribute all_lookups.
5 6 7 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 5 def all_lookups @all_lookups end |
#named_lookups ⇒ Object (readonly)
Returns the value of attribute named_lookups.
5 6 7 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 5 def named_lookups @named_lookups end |
Instance Method Details
#[](index) ⇒ Object
48 49 50 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 48 def [](index) @all_lookups[index] end |
#add(lookup) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 12 def add(lookup) return false if is_full @all_lookups.push(lookup) return true if lookup.input_id == nil @named_lookups[lookup.input_id] = lookup true end |
#clear ⇒ Object
23 24 25 26 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 23 def clear @named_lookups.clear @all_lookups.clear end |
#each(&block) ⇒ Object
44 45 46 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 44 def each(&block) @all_lookups.each(&block) end |
#get_by_index(index) ⇒ Object
40 41 42 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 40 def get_by_index(index) @all_lookups[index] end |
#get_by_input_id(input_id) ⇒ Object
36 37 38 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 36 def get_by_input_id(input_id) @named_lookups[input_id] end |
#is_full ⇒ Object
28 29 30 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 28 def is_full size >= MAX_BATCH_SIZE end |
#size ⇒ Object
32 33 34 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 32 def size @all_lookups.length end |