Class: Wheretocard::LineItem

Inherits:
Object
  • Object
show all
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)

Returns:

  • (Array)

    Errors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ LineItem

Initializer to transform a Hash into an Payment object

Parameters:

  • args (Hash) (defaults to: nil)


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

#barcodeObject

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
  @barcode
end

#descriptionObject

Returns the value of attribute description.



21
22
23
# File 'lib/wheretocard/line_item.rb', line 21

def description
  @description
end

#errorsObject

Returns the value of attribute errors.



13
14
15
# File 'lib/wheretocard/line_item.rb', line 13

def errors
  @errors
end

#priceObject

Returns the value of attribute price.



20
21
22
# File 'lib/wheretocard/line_item.rb', line 20

def price
  @price
end

#product_codeObject

Returns the value of attribute product_code.



14
15
16
# File 'lib/wheretocard/line_item.rb', line 14

def product_code
  @product_code
end

#quantityObject

Returns the value of attribute quantity.



18
19
20
# File 'lib/wheretocard/line_item.rb', line 18

def quantity
  @quantity
end

#ticket_refObject

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_fromObject

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_untilObject

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

#validateObject



39
40
41
42
43
# File 'lib/wheretocard/line_item.rb', line 39

def validate
  if barcode && quantity && quantity > 1
    raise WheretocardError.new(self), "Quantity cannot be greater than 1 if a barcode is specified."
  end
end