Class: Harvestime::Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/harvestime/invoice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def amount
  @amount
end

#client_idObject

Returns the value of attribute client_id.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def client_id
  @client_id
end

#client_keyObject

Returns the value of attribute client_key.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def client_key
  @client_key
end

#created_atObject

Returns the value of attribute created_at.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def created_at
  @created_at
end

#created_byObject

Returns the value of attribute created_by.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def created_by
  @created_by
end

#currency_typeObject

Returns the value of attribute currency_type.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def currency_type
  @currency_type
end

#discount_amountObject

Returns the value of attribute discount_amount.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def discount_amount
  @discount_amount
end

#due_amountObject

Returns the value of attribute due_amount.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def due_amount
  @due_amount
end

#due_dateObject

Returns the value of attribute due_date.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def due_date
  @due_date
end

#estimate_idObject

Returns the value of attribute estimate_id.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def estimate_id
  @estimate_id
end

#human_due_dateObject

Returns the value of attribute human_due_date.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def human_due_date
  @human_due_date
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def id
  @id
end

#notesObject

Returns the value of attribute notes.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def notes
  @notes
end

#numberObject

Returns the value of attribute number.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def number
  @number
end

#period_endObject

Returns the value of attribute period_end.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def period_end
  @period_end
end

#period_startObject

Returns the value of attribute period_start.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def period_start
  @period_start
end

#purchase_orderObject

Returns the value of attribute purchase_order.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def purchase_order
  @purchase_order
end

#recurring_invoice_idObject

Returns the value of attribute recurring_invoice_id.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def recurring_invoice_id
  @recurring_invoice_id
end

#retainer_invoice_idObject

Returns the value of attribute retainer_invoice_id.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def retainer_invoice_id
  @retainer_invoice_id
end

#stateObject

Returns the value of attribute state.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def state
  @state
end

#tax_1Object

Returns the value of attribute tax_1.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def tax_1
  @tax_1
end

#tax_1_amountObject

Returns the value of attribute tax_1_amount.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def tax_1_amount
  @tax_1_amount
end

#tax_2Object

Returns the value of attribute tax_2.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def tax_2
  @tax_2
end

#tax_2_amountObject

Returns the value of attribute tax_2_amount.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def tax_2_amount
  @tax_2_amount
end

#updated_atObject

Returns the value of attribute updated_at.



6
7
8
# File 'lib/harvestime/invoice.rb', line 6

def updated_at
  @updated_at
end

Instance Method Details

#instantiate_valuesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/harvestime/invoice.rb', line 21

def instantiate_values
  @id                   = @invoice.xpath('//id').text.to_i
  @amount               = @invoice.xpath('//amount').text.to_f
  @due_amount           = @invoice.xpath('//due-amount').text.to_f
  @due_date             = parse_date(@invoice.xpath('//due-at').text)
  @human_due_date       = @invoice.xpath('//due-at-human-format').text 
  @period_end           = parse_date(@invoice.xpath('//period-end').text)
  @period_start         = parse_date(@invoice.xpath('//period-start').text)
  @client_id            = @invoice.xpath('//client-id').text.to_i
  @currency_type        = @invoice.xpath('//currency').text
  @number               = @invoice.xpath('//number').text.to_i
  @purchase_order       = @invoice.xpath('//purchase-order').text
  @client_key           = @invoice.xpath('//client-key').text
  @state                = @invoice.xpath('//state').text
  @tax_1                = @invoice.xpath('//tax').text.to_f
  @tax_2                = @invoice.xpath('//tax2').text.to_f
  @tax_1_amount         = @invoice.xpath('//tax-amount').text.to_f
  @tax_2_amount         = @invoice.xpath('//tax-amount2').text.to_f
  @discount_amount      = @invoice.xpath('//discount-amount').text.to_f
  @discount             = @invoice.xpath('//discount').text.to_f
  @recurring_invoice_id = @invoice.xpath('//recurring-invoice-id').text.to_i
  @retainer_invoice_id  = @invoice.xpath('//retainer-id').text.to_i
  @updated_at           = parse_date(@invoice.xpath('//updated-at').text)
  @created_at           = parse_date(@invoice.xpath('//created-at').text)
  @created_by           = @invoice.xpath('//created-by-id').text.to_i
  @notes                = @invoice.xpath('//notes').text
  @estimate_id          = @invoice.xpath('//estimate-id').text.to_i
end

#parse_date(string) ⇒ Object



50
51
52
53
54
# File 'lib/harvestime/invoice.rb', line 50

def parse_date(string)
  Date.parse(string)
rescue
  Time.new("").to_date
end

#retrieve(path) ⇒ Object



14
15
16
17
18
19
# File 'lib/harvestime/invoice.rb', line 14

def retrieve(path)
  file     = File.open(path.to_s)
  @invoice = Nokogiri::XML(file)
  instantiate_values
  return :success
end