Class: InvoicesView

Inherits:
Object
  • Object
show all
Includes:
ViewsHelpers
Defined in:
lib/invoices/views/invoices_view.rb

Instance Method Summary collapse

Methods included from ViewsHelpers

#compare_length, #divider, #format_hrs, #format_rate

Constructor Details

#initialize(invoice, biller, client) ⇒ InvoicesView

Returns a new instance of InvoicesView.



6
7
8
# File 'lib/invoices/views/invoices_view.rb', line 6

def initialize(invoice, biller, client)
  @invoice, @biller, @client = invoice, biller, client
end

Instance Method Details

#address(person) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/invoices/views/invoices_view.rb', line 22

def address(person)
  line(person.name, " ") +
  line(person.street1, " ") + 
  line(person.street2, " ") +  
  line(person.city + ", " + person.state + " " + person.zip, " ") + 
  line(person.phone, " ") +
  line(person.email, " ")
end

#border_bottomObject



39
40
41
42
# File 'lib/invoices/views/invoices_view.rb', line 39

def border_bottom
  ("\n" * 2) + 
  "----+----------+------------------------------------------+-----+------+" + "\n"
end

#border_topObject



35
36
37
38
# File 'lib/invoices/views/invoices_view.rb', line 35

def border_top
  "----+-- DATE --+------------- COMMIT MESSAGE -------------+ HRS + RATE +" + 
  ("\n" * 2)
end

#gridObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/invoices/views/invoices_view.rb', line 34

def grid
  def border_top
    "----+-- DATE --+------------- COMMIT MESSAGE -------------+ HRS + RATE +" + 
    ("\n" * 2)
  end
  def border_bottom
    ("\n" * 2) + 
    "----+----------+------------------------------------------+-----+------+" + "\n"
  end
  def total
    "TOTALS:" + (" " * 53) + "#{format_hrs(@invoice.total_hrs)}" + 
    divider + "#{format_rate(@invoice.total_cost)}" + "\n"
  end
  border_top + LineItemsView.new.prepare(@invoice.line_items_array).join("\n") +
  border_bottom + total
end

#headerObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/invoices/views/invoices_view.rb', line 9

def header
  def space(chars)
    " " * (72 - chars) # 72 chars in page width was, 
  end                  # traditionally, the most common
  def line(left, right)
    s = space(left.length + right.length)
    l = left + s + right + "\n"
    if l.strip.empty?
      ""
    else
      l
    end
  end
  def address(person)
    line(person.name, " ") +
    line(person.street1, " ") + 
    line(person.street2, " ") +  
    line(person.city + ", " + person.state + " " + person.zip, " ") + 
    line(person.phone, " ") +
    line(person.email, " ")
  end
  line("INVOICE #" + @invoice.format_number, @invoice.date) + "\n" +
  address(@biller) + "\n" * 2 + 
  line("BILL TO:", "") + address(@client) + "\n" * 2
end

#line(left, right) ⇒ Object

traditionally, the most common



13
14
15
16
17
18
19
20
21
# File 'lib/invoices/views/invoices_view.rb', line 13

def line(left, right)
  s = space(left.length + right.length)
  l = left + s + right + "\n"
  if l.strip.empty?
    ""
  else
    l
  end
end

#renderObject



50
51
52
# File 'lib/invoices/views/invoices_view.rb', line 50

def render
  header + grid
end

#space(chars) ⇒ Object



10
11
12
# File 'lib/invoices/views/invoices_view.rb', line 10

def space(chars)
  " " * (72 - chars) # 72 chars in page width was, 
end

#totalObject



43
44
45
46
# File 'lib/invoices/views/invoices_view.rb', line 43

def total
  "TOTALS:" + (" " * 53) + "#{format_hrs(@invoice.total_hrs)}" + 
  divider + "#{format_rate(@invoice.total_cost)}" + "\n"
end