Class: Wheretocard::LineItem
- Inherits:
-
Object
- Object
- Wheretocard::LineItem
- Defined in:
- lib/wheretocard/line_item.rb
Overview
Object representing a line item with attributes provided by WTC required args:
-
product_code (string)
-
price (integer - cents)
-
valid_from (DateTime / Date)
-
valid_until (DateTime / Date)
-
barcode (string) OR quantity (integer)
Instance Attribute Summary collapse
-
#barcode ⇒ Object
If a barcode is given, it’ll be used.
-
#description ⇒ Object
Returns the value of attribute description.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#price ⇒ Object
Returns the value of attribute price.
-
#product_code ⇒ Object
Returns the value of attribute product_code.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#ticket_ref ⇒ Object
Returns the value of attribute ticket_ref.
-
#valid_from ⇒ Object
Returns the value of attribute valid_from.
-
#valid_until ⇒ Object
Returns the value of attribute valid_until.
Instance Method Summary collapse
-
#initialize(args = nil) ⇒ LineItem
constructor
Initializer to transform a
Hash
into an Payment object. - #validate ⇒ Object
Constructor Details
#initialize(args = nil) ⇒ LineItem
Initializer to transform a Hash
into an Payment object
29 30 31 32 33 34 35 36 37 |
# File 'lib/wheretocard/line_item.rb', line 29 def initialize(args=nil) @quantity = 1 return if args.nil? args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end validate end |
Instance Attribute Details
#barcode ⇒ Object
If a barcode is given, it’ll be used. There is no check for uniqueness. If no barcode is given, WtC will generate a unique one.
17 18 19 |
# File 'lib/wheretocard/line_item.rb', line 17 def @barcode end |
#description ⇒ Object
Returns the value of attribute description.
21 22 23 |
# File 'lib/wheretocard/line_item.rb', line 21 def description @description end |
#errors ⇒ Object
Returns the value of attribute errors.
13 14 15 |
# File 'lib/wheretocard/line_item.rb', line 13 def errors @errors end |
#price ⇒ Object
Returns the value of attribute price.
20 21 22 |
# File 'lib/wheretocard/line_item.rb', line 20 def price @price end |
#product_code ⇒ Object
Returns the value of attribute product_code.
14 15 16 |
# File 'lib/wheretocard/line_item.rb', line 14 def product_code @product_code end |
#quantity ⇒ Object
Returns the value of attribute quantity.
18 19 20 |
# File 'lib/wheretocard/line_item.rb', line 18 def quantity @quantity end |
#ticket_ref ⇒ Object
Returns the value of attribute ticket_ref.
19 20 21 |
# File 'lib/wheretocard/line_item.rb', line 19 def ticket_ref @ticket_ref end |
#valid_from ⇒ Object
Returns the value of attribute valid_from.
22 23 24 |
# File 'lib/wheretocard/line_item.rb', line 22 def valid_from @valid_from end |
#valid_until ⇒ Object
Returns the value of attribute valid_until.
23 24 25 |
# File 'lib/wheretocard/line_item.rb', line 23 def valid_until @valid_until end |
Instance Method Details
#validate ⇒ Object
39 40 41 42 43 |
# File 'lib/wheretocard/line_item.rb', line 39 def validate if && quantity && quantity > 1 raise WheretocardError.new(self), "Quantity cannot be greater than 1 if a barcode is specified." end end |