Class: Product

Inherits:
Object
  • Object
show all
Defined in:
lib/wunder/product.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_code, name, price, no_validate = false) ⇒ Product

Returns a new instance of Product.



4
5
6
7
8
9
10
# File 'lib/wunder/product.rb', line 4

def initialize(product_code, name, price, no_validate = false)
  @product_code = product_code
  @name = name
  @price = price.nil? ? nil : BigDecimal(price, 2)

  validate if no_validate == false
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/wunder/product.rb', line 2

def name
  @name
end

#priceObject

Returns the value of attribute price.



2
3
4
# File 'lib/wunder/product.rb', line 2

def price
  @price
end

#product_codeObject

Returns the value of attribute product_code.



2
3
4
# File 'lib/wunder/product.rb', line 2

def product_code
  @product_code
end

Instance Method Details

#validateObject



12
13
14
15
16
17
# File 'lib/wunder/product.rb', line 12

def validate
  [product_code, name, price].each do |parameter|
    raise ArgumentError, "ProductParameterMissing" if parameter.nil?
  end
  nil
end