Class: LineItem
- Inherits:
-
Object
- Object
- LineItem
- Defined in:
- lib/invoices/models/line_item.rb
Instance Attribute Summary collapse
-
#cost ⇒ Object
Returns the value of attribute cost.
-
#date ⇒ Object
Returns the value of attribute date.
-
#hrs ⇒ Object
Returns the value of attribute hrs.
-
#invoice_number ⇒ Object
Returns the value of attribute invoice_number.
-
#line_number ⇒ Object
Returns the value of attribute line_number.
-
#msg ⇒ Object
Returns the value of attribute msg.
-
#rate ⇒ Object
Returns the value of attribute rate.
Instance Method Summary collapse
- #find_by_invoice_number(invoice_number, *boolean) ⇒ Object
-
#initialize(invoice_number, line_number, date, msg, hrs, rate) ⇒ LineItem
constructor
A new instance of LineItem.
- #save(*boolean) ⇒ Object
Constructor Details
#initialize(invoice_number, line_number, date, msg, hrs, rate) ⇒ LineItem
Returns a new instance of LineItem.
4 5 6 7 8 9 10 11 12 |
# File 'lib/invoices/models/line_item.rb', line 4 def initialize(invoice_number, line_number, date, msg, hrs, rate) @invoice_number = invoice_number @line_number = line_number @date = date.to_s @msg = msg @hrs = hrs.to_i @rate = rate.to_i @cost = @hrs * @rate end |
Instance Attribute Details
#cost ⇒ Object
Returns the value of attribute cost.
2 3 4 |
# File 'lib/invoices/models/line_item.rb', line 2 def cost @cost end |
#date ⇒ Object
Returns the value of attribute date.
2 3 4 |
# File 'lib/invoices/models/line_item.rb', line 2 def date @date end |
#hrs ⇒ Object
Returns the value of attribute hrs.
2 3 4 |
# File 'lib/invoices/models/line_item.rb', line 2 def hrs @hrs end |
#invoice_number ⇒ Object
Returns the value of attribute invoice_number.
2 3 4 |
# File 'lib/invoices/models/line_item.rb', line 2 def invoice_number @invoice_number end |
#line_number ⇒ Object
Returns the value of attribute line_number.
2 3 4 |
# File 'lib/invoices/models/line_item.rb', line 2 def line_number @line_number end |
#msg ⇒ Object
Returns the value of attribute msg.
2 3 4 |
# File 'lib/invoices/models/line_item.rb', line 2 def msg @msg end |
#rate ⇒ Object
Returns the value of attribute rate.
2 3 4 |
# File 'lib/invoices/models/line_item.rb', line 2 def rate @rate end |
Instance Method Details
#find_by_invoice_number(invoice_number, *boolean) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/invoices/models/line_item.rb', line 13 def find_by_invoice_number(invoice_number, *boolean) items = choose_db(*boolean).execute("select * from line_items where invoice_number = #{invoice_number}") items.map! do |line| LineItem.new(line[0], line[1], line[2], line[3], line[4].to_s, line[5].to_s) end items end |
#save(*boolean) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/invoices/models/line_item.rb', line 21 def save(*boolean) choose_db(*boolean).execute("INSERT INTO line_items (invoice_number, line_number, commit_date, commit_msg, hrs, rate, cost) VALUES (?, ?, ?, ?, ?, ?, ?)", [@invoice_number, @line_number, @date, @msg, @hrs, @rate, @cost]) end |