Class: Clinvoice::Data
- Inherits:
-
Object
- Object
- Clinvoice::Data
- Defined in:
- lib/clinvoice/data.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#contractor ⇒ Object
readonly
Returns the value of attribute contractor.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#due_date ⇒ Object
readonly
Returns the value of attribute due_date.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#invoice_id ⇒ Object
readonly
Returns the value of attribute invoice_id.
-
#issue_date ⇒ Object
readonly
Returns the value of attribute issue_date.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(file) ⇒ Data
constructor
A new instance of Data.
- #pdf_file ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/clinvoice/data.rb', line 7 def client @client end |
#contractor ⇒ Object (readonly)
Returns the value of attribute contractor.
7 8 9 |
# File 'lib/clinvoice/data.rb', line 7 def contractor @contractor end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
7 8 9 |
# File 'lib/clinvoice/data.rb', line 7 def currency @currency end |
#due_date ⇒ Object (readonly)
Returns the value of attribute due_date.
7 8 9 |
# File 'lib/clinvoice/data.rb', line 7 def due_date @due_date end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/clinvoice/data.rb', line 7 def file @file end |
#invoice_id ⇒ Object (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_date ⇒ Object (readonly)
Returns the value of attribute issue_date.
7 8 9 |
# File 'lib/clinvoice/data.rb', line 7 def issue_date @issue_date end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/clinvoice/data.rb', line 7 def items @items end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
7 8 9 |
# File 'lib/clinvoice/data.rb', line 7 def notes @notes end |
#total ⇒ Object (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_file ⇒ Object
44 45 46 |
# File 'lib/clinvoice/data.rb', line 44 def pdf_file "#{file.gsub('.yml', '')}.pdf" end |