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.



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

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']
  @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

#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

#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