Class: Batch

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/smartystreets_ruby_sdk/batch.rb

Constant Summary collapse

MAX_BATCH_SIZE =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBatch

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_lookupsObject (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_lookupsObject (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

#clearObject



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_fullObject



28
29
30
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 28

def is_full
  size >= MAX_BATCH_SIZE
end

#sizeObject



32
33
34
# File 'lib/smartystreets_ruby_sdk/batch.rb', line 32

def size
  @all_lookups.length
end