Class: Clinvoice::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/clinvoice/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Data

Returns a new instance of Data.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/clinvoice/data.rb', line 18

def initialize(file)
  filename = file.end_with?('.yml') ? file : "#{file}.yml"

  data = YAML.load_file(filename)['data']

  @file = file
  @invoice_id = data['id']
  @currency = data['currency']
  @issue_date = data['issue_date']
  @contractor = data['contractor']
  @issue_date = data['issue_date']
  @due_date = data['due_date']
  @client = data['client']
  @items = data['items'].map do |item|
    [
      item['description'],
      item['unit_cost'],
      item['quantity'],
      item['quantity'] * item['unit_cost']
    ]
  end

  @notes = data['notes']
  @total = @items.map(&:last).sum
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/clinvoice/data.rb', line 7

def client
  @client
end

#contractorObject (readonly)

Returns the value of attribute contractor.



7
8
9
# File 'lib/clinvoice/data.rb', line 7

def contractor
  @contractor
end

#currencyObject (readonly)

Returns the value of attribute currency.



7
8
9
# File 'lib/clinvoice/data.rb', line 7

def currency
  @currency
end

#due_dateObject (readonly)

Returns the value of attribute due_date.



7
8
9
# File 'lib/clinvoice/data.rb', line 7

def due_date
  @due_date
end

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/clinvoice/data.rb', line 7

def file
  @file
end

#invoice_idObject (readonly)

Returns the value of attribute invoice_id.



7
8
9
# File 'lib/clinvoice/data.rb', line 7

def invoice_id
  @invoice_id
end

#issue_dateObject (readonly)

Returns the value of attribute issue_date.



7
8
9
# File 'lib/clinvoice/data.rb', line 7

def issue_date
  @issue_date
end

#itemsObject (readonly)

Returns the value of attribute items.



7
8
9
# File 'lib/clinvoice/data.rb', line 7

def items
  @items
end

#notesObject (readonly)

Returns the value of attribute notes.



7
8
9
# File 'lib/clinvoice/data.rb', line 7

def notes
  @notes
end

#totalObject (readonly)

Returns the value of attribute total.



7
8
9
# File 'lib/clinvoice/data.rb', line 7

def total
  @total
end

Instance Method Details

#pdf_fileObject



44
45
46
# File 'lib/clinvoice/data.rb', line 44

def pdf_file
  "#{file.gsub('.yml', '')}.pdf"
end