Class: SmartyStreets::Batch
- Inherits:
-
Object
- Object
- SmartyStreets::Batch
- Includes:
- Enumerable
- Defined in:
- lib/smartystreets_ruby_sdk/batch.rb
Overview
The Batch class is used to send up to 100 lookups at once
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
- #empty? ⇒ Boolean
- #full? ⇒ Boolean
- #get_by_index(index) ⇒ Object
- #get_by_input_id(input_id) ⇒ Object
-
#initialize ⇒ Batch
constructor
A new instance of Batch.
- #size ⇒ Object
Constructor Details
#initialize ⇒ Batch
Returns a new instance of Batch.
9 10 11 12 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 9 def initialize @named_lookups = {} @all_lookups = [] end |
Instance Attribute Details
#all_lookups ⇒ Object (readonly)
Returns the value of attribute all_lookups.
7 8 9 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 7 def all_lookups @all_lookups end |
#named_lookups ⇒ Object (readonly)
Returns the value of attribute named_lookups.
7 8 9 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 7 def named_lookups @named_lookups end |
Instance Method Details
#[](index) ⇒ Object
54 55 56 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 54 def [](index) @all_lookups[index] end |
#add(lookup) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 14 def add(lookup) return false if full? @all_lookups.push(lookup) return true if lookup.input_id.nil? @named_lookups[lookup.input_id] = lookup true end |
#clear ⇒ Object
25 26 27 28 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 25 def clear @named_lookups.clear @all_lookups.clear end |
#each(&block) ⇒ Object
50 51 52 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 50 def each(&block) @all_lookups.each(&block) end |
#empty? ⇒ Boolean
34 35 36 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 34 def empty? size.zero? end |
#full? ⇒ Boolean
30 31 32 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 30 def full? size >= MAX_BATCH_SIZE end |
#get_by_index(index) ⇒ Object
46 47 48 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 46 def get_by_index(index) @all_lookups[index] end |
#get_by_input_id(input_id) ⇒ Object
42 43 44 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 42 def get_by_input_id(input_id) @named_lookups[input_id] end |
#size ⇒ Object
38 39 40 |
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 38 def size @all_lookups.length end |