Class: Product
- Inherits:
-
Object
- Object
- Product
- Defined in:
- lib/wunder/product.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#price ⇒ Object
Returns the value of attribute price.
-
#product_code ⇒ Object
Returns the value of attribute product_code.
Instance Method Summary collapse
-
#initialize(product_code, name, price, no_validate = false) ⇒ Product
constructor
A new instance of Product.
- #validate ⇒ Object
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
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/wunder/product.rb', line 2 def name @name end |
#price ⇒ Object
Returns the value of attribute price.
2 3 4 |
# File 'lib/wunder/product.rb', line 2 def price @price end |
#product_code ⇒ Object
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
#validate ⇒ Object
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 |