Module: Pombo::Package::Format

Defined in:
lib/pombo/package/format.rb

Overview

The formats are pre-defined objects with the information provided by the Correios

Class Method Summary collapse

Class Method Details

.allArray<OpenStruct>

List all formats supported by delivery services

Examples:

Pombo::Package::Format.all
# => [
# =>    #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
# =>    ....
# => ]

Returns:

  • (Array<OpenStruct>)

    with the data structure representing a format


15
16
17
18
19
20
21
# File 'lib/pombo/package/format.rb', line 15

def self.all
  [
    OpenStruct.new(code: 1, name: Pombo.t('formats.1'), max_length: 105, min_length: 16, max_height: 105, min_height: 2, max_width: 105, min_width: 11, max_dimension: 200),
    OpenStruct.new(code: 2, name: Pombo.t('formats.2'), max_length: 105, min_length: 18, max_diameter: 91, min_diameter: 5, max_dimension: 200),
    OpenStruct.new(code: 3, name: Pombo.t('formats.3'), max_length: 60, min_length: 16, max_width: 60, min_width: 11, max_weight: 1)
  ]
end

.find(code) ⇒ OpenStruct

Find a specific format by code or by name

Examples:

Pombo::Package::Format.find '3'
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>

# => Or

Pombo::Package::Format.find 'envelope'
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>

Parameters:

  • code (String)

    code or the format name, to box `1, box or package`, to roll `2, roll or prism` and to envelope `3 or envelope`

Returns:

  • (OpenStruct)

    the data structure representing a format


34
35
36
37
38
39
40
41
42
43
# File 'lib/pombo/package/format.rb', line 34

def self.find(code)
  case code.to_s
  when '1', 'box', 'package'
    all[0]
  when '2', 'roll', 'prism'
    all[1]
  when '3', 'envelope'
    all[2]
  end
end