Class: Pombo::Package::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/pombo/package/item.rb

Overview

Item is the object that will be sent in the package through the Brazilian Post Service

By default the quantity is 1 and the format is Pombo::Package::Format.find(:box).code

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Item

Returns a new instance of Item


8
9
10
11
# File 'lib/pombo/package/item.rb', line 8

def initialize(**args)
  args = { weight: 0.0, length: 0.0, height: 0.0, width: 0.0, diameter: 0.0, quantity: 1, format: Pombo::Package::Format.find(:box).code }.merge(args)
  args.each { |key, value| __send__("#{ key }=", value) }
end

Instance Attribute Details

#diameterObject

Returns the value of attribute diameter


6
7
8
# File 'lib/pombo/package/item.rb', line 6

def diameter
  @diameter
end

#formatObject

Returns the value of attribute format


6
7
8
# File 'lib/pombo/package/item.rb', line 6

def format
  @format
end

#heightObject

Returns the value of attribute height


6
7
8
# File 'lib/pombo/package/item.rb', line 6

def height
  @height
end

#lengthObject

Returns the value of attribute length


6
7
8
# File 'lib/pombo/package/item.rb', line 6

def length
  @length
end

#quantityObject

Returns the value of attribute quantity


6
7
8
# File 'lib/pombo/package/item.rb', line 6

def quantity
  @quantity
end

#weightObject

Returns the value of attribute weight


6
7
8
# File 'lib/pombo/package/item.rb', line 6

def weight
  @weight
end

#widthObject

Returns the value of attribute width


6
7
8
# File 'lib/pombo/package/item.rb', line 6

def width
  @width
end

Instance Method Details

#volumeFloat

Calculates the volume item in accordance with the format

Returns:

  • (Float)

    the volume value


15
16
17
18
19
20
21
22
23
24
# File 'lib/pombo/package/item.rb', line 15

def volume
  case format
  when Pombo::Package::Format.find(:box).code
    package_volume * quantity
  when Pombo::Package::Format.find(:roll).code
    roll_volume * quantity
  when Pombo::Package::Format.find(:envelope).code
    0
  end
end