Class: Belpost::Models::CustomsDeclaration
- Inherits:
-
Object
- Object
- Belpost::Models::CustomsDeclaration
- Defined in:
- lib/belpost/models/customs_declaration.rb
Constant Summary collapse
- VALID_CATEGORIES =
%w[gift documents sample returned_goods merchandise other].freeze
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#certificates ⇒ Object
readonly
Returns the value of attribute certificates.
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#explanation ⇒ Object
readonly
Returns the value of attribute explanation.
-
#invoice ⇒ Object
readonly
Returns the value of attribute invoice.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#licences ⇒ Object
readonly
Returns the value of attribute licences.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
Instance Method Summary collapse
- #add_item(item_data) ⇒ Object
-
#initialize(data = {}) ⇒ CustomsDeclaration
constructor
A new instance of CustomsDeclaration.
- #set_category(category) ⇒ Object
- #set_price(currency, value) ⇒ Object
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(data = {}) ⇒ CustomsDeclaration
Returns a new instance of CustomsDeclaration.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/belpost/models/customs_declaration.rb', line 10 def initialize(data = {}) @items = data[:items] || [] @price = data[:price] || {} @category = data[:category] @explanation = data[:explanation] @comments = data[:comments] @invoice = data[:invoice] @licences = data[:licences] || [] @certificates = data[:certificates] || [] end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
8 9 10 |
# File 'lib/belpost/models/customs_declaration.rb', line 8 def category @category end |
#certificates ⇒ Object (readonly)
Returns the value of attribute certificates.
8 9 10 |
# File 'lib/belpost/models/customs_declaration.rb', line 8 def certificates @certificates end |
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
8 9 10 |
# File 'lib/belpost/models/customs_declaration.rb', line 8 def comments @comments end |
#explanation ⇒ Object (readonly)
Returns the value of attribute explanation.
8 9 10 |
# File 'lib/belpost/models/customs_declaration.rb', line 8 def explanation @explanation end |
#invoice ⇒ Object (readonly)
Returns the value of attribute invoice.
8 9 10 |
# File 'lib/belpost/models/customs_declaration.rb', line 8 def invoice @invoice end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
8 9 10 |
# File 'lib/belpost/models/customs_declaration.rb', line 8 def items @items end |
#licences ⇒ Object (readonly)
Returns the value of attribute licences.
8 9 10 |
# File 'lib/belpost/models/customs_declaration.rb', line 8 def licences @licences end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
8 9 10 |
# File 'lib/belpost/models/customs_declaration.rb', line 8 def price @price end |
Instance Method Details
#add_item(item_data) ⇒ Object
21 22 23 |
# File 'lib/belpost/models/customs_declaration.rb', line 21 def add_item(item_data) @items << item_data end |
#set_category(category) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/belpost/models/customs_declaration.rb', line 29 def set_category(category) unless VALID_CATEGORIES.include?(category) raise ValidationError, "Invalid category. Must be one of: #{VALID_CATEGORIES.join(', ')}" end @category = category end |
#set_price(currency, value) ⇒ Object
25 26 27 |
# File 'lib/belpost/models/customs_declaration.rb', line 25 def set_price(currency, value) @price = { currency: currency, value: value } end |
#to_h ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/belpost/models/customs_declaration.rb', line 37 def to_h { items: @items, price: @price, category: @category, explanation: @explanation, comments: @comments, invoice: @invoice, licences: @licences, certificates: @certificates }.compact end |
#valid? ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/belpost/models/customs_declaration.rb', line 50 def valid? return false if @category && !VALID_CATEGORIES.include?(@category) return false if @category == "other" && @explanation.nil? if %w[merchandise sample returned_goods].include?(@category) return false if @items.empty? return false if @price.empty? end true end |