Top Level Namespace

Defined Under Namespace

Modules: ActivityTypeModelHelper, AdminLayoutActiveScaffoldHelper, AdminLayoutHelper, ApplicationHelper, AuthenticationHelper, BriskBills, ExtensibleObjectHelper, HasCredentialModelHelper, InvoicePdfHelper, IsActiveModelHelper, MoneyModelHelper, PDF, Rails Classes: Activity, ActivityType, ApplicationController, AuthenticationController, Client, ClientEventlog, ClientFinancialTransaction, ClientRepresentative, Credential, CredentialDisabled, CredentialLockedOut, Employee, EmployeeClientLaborRate, InstanceGenerator, Invoice, InvoicePayment, NavigationLink, NavigationMenu, Notifier, Payment, PaymentMethod, ResourceNotFound, SerializableProc, Setting, SlimtimerTask, SlimtimerTimeEntry, String

Constant Summary collapse

BRISKBILLS_ROOT =
File.expand_path(File.join(File.dirname(__FILE__), ".."))
RAILS_ROOT =

Don’t change this file! Configure your app in config/environment.rb and config/environments/*.rb

File.expand_path("#{File.dirname(__FILE__)}/..")

Instance Method Summary collapse

Instance Method Details

#humanize_bool(v) ⇒ Object



46
47
48
# File 'lib/libpptable.rb', line 46

def humanize_bool(v)
  v ? "Yes" : "No"
end

#pp_table(header, data) ⇒ Object

This got a little complicated. But, it works well ansd should be reuseable. I didn’t put a check in here to ensure that every data row is of the same length as the header. But they should be - or else weirdness will ensue



6
7
8
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
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/libpptable.rb', line 6

def pp_table(header,data)
    row_prefix    = "| "
    row_suffix    = " |"
    col_join      = " | "
    header_colsep = "-+-"
    colsep_prefix = "+-"
    colsep_suffix = "-+"
    table_corner  = "+"

    # This is a quick way to calculate each column of the data's max string-width:
    array_col_widths = ([header]+data).inject(Array.new(header.length,0)){|ret,row|
       row.each_with_index{|f,i| ret[i] = f.length if f.to_s.length > ret[i] }
       ret
    }

    col_sprintf = row_prefix+array_col_widths.collect{|w| "%-#{w}s" }.join(col_join)+row_suffix

    table_width = (
      array_col_widths+[
        (array_col_widths.length-1)*col_join.length,
        row_prefix.length,
        row_suffix.length
      ]
    ).reduce(:+)

    table_ends = [table_corner,"-" * (table_width-table_corner.length*2),table_corner].join

    puts [
      table_ends,                        # Table-top
      col_sprintf % header,              # Header row
      [                                  # Header/data Separator
        colsep_prefix,
        array_col_widths.collect{|w| "-" * w}.join(header_colsep),
        colsep_suffix
      ].join,
      data.collect{|a| col_sprintf % a}, # Data rows
      table_ends,                        # Table-bottom
    ].flatten.join("\n")
end