Class: CzechPost::CodeGenerator::OrderNumber

Inherits:
Object
  • Object
show all
Defined in:
lib/czech_post/code_generator/order_number.rb

Constant Summary collapse

MAX_SIZE =
9

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order_id, client_id) ⇒ OrderNumber

Returns a new instance of OrderNumber.



8
9
10
11
12
# File 'lib/czech_post/code_generator/order_number.rb', line 8

def initialize(order_id, client_id)
  @order_id = order_id.to_s
  @client_id = client_id.to_s
  raise(CzechPost::CodeGenerator::Errors::InvalidOrderNumberId, order_id) unless valid?
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



6
7
8
# File 'lib/czech_post/code_generator/order_number.rb', line 6

def client_id
  @client_id
end

#order_idObject (readonly)

Returns the value of attribute order_id.



6
7
8
# File 'lib/czech_post/code_generator/order_number.rb', line 6

def order_id
  @order_id
end

Instance Method Details

#idObject



14
15
16
# File 'lib/czech_post/code_generator/order_number.rb', line 14

def id
  @id ||= order_id.to_s.rjust(size, '0')
end

#sizeObject



23
24
25
# File 'lib/czech_post/code_generator/order_number.rb', line 23

def size
  MAX_SIZE - client_id.length
end

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/czech_post/code_generator/order_number.rb', line 18

def valid?
  return false if order_id == '' || client_id == ''
  id.length == size
end