Class: Invoicing::LedgerItem::RenderHTML::HTMLOutputBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/invoicing/ledger_item/render_html.rb

Overview

:nodoc:

Constant Summary collapse

HTML_ESCAPE =
{ '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ledger_item, options) ⇒ HTMLOutputBuilder

Returns a new instance of HTMLOutputBuilder.



36
37
38
39
40
41
42
43
# File 'lib/invoicing/ledger_item/render_html.rb', line 36

def initialize(ledger_item, options)
  @ledger_item = ledger_item
  @options = default_options
  @options.update(options)
  @custom_fragments = {}
  total_amount = get(:total_amount)
  @factor = (total_amount && total_amount < BigDecimal('0')) ? BigDecimal('-1') : BigDecimal('1')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object

foo { block } => call block when invoking fragment foo foo “string” => return string when invoking fragment foo invoke_foo => invoke fragment foo; if none set, delegate to default_foo



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/invoicing/ledger_item/render_html.rb', line 65

def method_missing(method_id, *args, &block)
  method_id = method_id.to_sym
  if method_id.to_s =~ /^invoke_(.*)$/
    method_id = $1.to_sym
    if custom_fragments[method_id]
      return custom_fragments[method_id].call(*args, &block)
    else
      return send("default_#{method_id}", *args, &block)
    end
  end
  
  return super unless respond_to? "default_#{method_id}"

  if block_given? && args.empty?
    custom_fragments[method_id] = proc &block
  elsif args.length == 1
    custom_fragments[method_id] = proc{ args[0].to_s }
  else
    raise ArgumentError, "#{method_id} expects exactly one value or block argument"
  end
end

Instance Attribute Details

#current_line_itemObject (readonly)

Returns the value of attribute current_line_item.



34
35
36
# File 'lib/invoicing/ledger_item/render_html.rb', line 34

def current_line_item
  @current_line_item
end

#custom_fragmentsObject (readonly)

Returns the value of attribute custom_fragments.



34
35
36
# File 'lib/invoicing/ledger_item/render_html.rb', line 34

def custom_fragments
  @custom_fragments
end

#factorObject (readonly)

Returns the value of attribute factor.



34
35
36
# File 'lib/invoicing/ledger_item/render_html.rb', line 34

def factor
  @factor
end

#ledger_itemObject (readonly)

Returns the value of attribute ledger_item.



34
35
36
# File 'lib/invoicing/ledger_item/render_html.rb', line 34

def ledger_item
  @ledger_item
end

#optionsObject (readonly)

Returns the value of attribute options.



34
35
36
# File 'lib/invoicing/ledger_item/render_html.rb', line 34

def options
  @options
end

Instance Method Details

#buildObject

Renders an invoice or credit note to HTML



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/invoicing/ledger_item/render_html.rb', line 122

def build
  addresses_table_deps = [:sender_label, :recipient_label, :sender_address, :recipient_address, {
    :sender_tax_number    => :tax_number_label,
    :recipient_tax_number => :tax_number_label
  }]
  
   = [{
    :identifier   =>  :identifier_label,
    :issue_date   => [:date_format, :issue_date_label],
    :period_start => [:date_format, :period_start_label],
    :period_end   => [:date_format, :period_end_label],
    :due_date     => [:date_format, :due_date_label]
  }]
  
  line_items_header_deps = [:line_tax_point_label, :line_quantity_label, :line_description_label,
    :line_net_amount_label, :line_tax_amount_label, :line_gross_amount_label]
    
  line_items_subtotal_deps = [:subtotal_label, :net_amount_label, :tax_amount_label,
    :gross_amount_label, {
    :net_amount => :net_amount_label,
    :tax_amount => :tax_amount_label,
    :total_amount => :gross_amount_label
  }]
  
  line_items_total_deps = [:total_label, :net_amount_label, :tax_amount_label,
    :gross_amount_label, {
    :net_amount => :net_amount_label,
    :tax_amount => :tax_amount_label,
    :total_amount => :gross_amount_label
  }]
  
  page_layout_deps = {
    :title_tag => :title,
    :addresses_table => addresses_table_deps,
    :metadata_table => ,
    :description_tag => :description,
    :line_items_table => [:line_items_list, {
      :line_items_header   => line_items_header_deps,
      :line_items_subtotal => line_items_subtotal_deps,
      :line_items_total    => line_items_total_deps
    }]
  }
  
  invoke_page_layout(params_hash(page_layout_deps))
end

#default_address(details) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/invoicing/ledger_item/render_html.rb', line 265

def default_address(details)
  details = details.symbolize_keys
  html =  "#{indent*3}<div class=\"fn org\">#{       h(details[:name])        }</div>\n"
  html << "#{indent*3}<div class=\"contact\">#{      h(details[:contact_name])}</div>\n"        unless details[:contact_name].blank?
  html << "#{indent*3}<div class=\"adr\">\n"
  html << "#{indent*4}<span class=\"street-address\">#{h(details[:address]).strip.gsub(/\n/, '<br />')}</span><br />\n"
  html << "#{indent*4}<span class=\"locality\">#{    h(details[:city])        }</span><br />\n" unless details[:city].blank?
  html << "#{indent*4}<span class=\"region\">#{      h(details[:state])       }</span><br />\n" unless details[:state].blank?
  html << "#{indent*4}<span class=\"postal-code\">#{ h(details[:postal_code]) }</span><br />\n" unless details[:postal_code].blank?
  html << "#{indent*4}<span class=\"country-name\">#{h(details[:country])     }</span>\n"       unless details[:country].blank?
  html << "#{indent*3}</div>\n"
end

#default_addresses_table(params) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/invoicing/ledger_item/render_html.rb', line 296

def default_addresses_table(params)
  html =  "#{indent*0}<table class=\"invoice addresses\">\n"
  html << "#{indent*1}<tr>\n"
  html << "#{indent*2}<th class=\"recipient\">#{params[:recipient_label]}</th>\n"
  html << "#{indent*2}<th class=\"sender\">#{params[:sender_label]}</th>\n"
  html << "#{indent*1}</tr>\n"
  html << "#{indent*1}<tr>\n"
  html << "#{indent*2}<td class=\"recipient vcard\">\n#{params[:recipient_address]}"
  html << "#{indent*2}</td>\n"
  html << "#{indent*2}<td class=\"sender vcard\">\n#{params[:sender_address]}"
  html << "#{indent*2}</td>\n"
  html << "#{indent*1}</tr>\n"
  html << "#{indent*1}<tr>\n"
  html << "#{indent*2}<td class=\"recipient\">\n"
  html << "#{indent*3}#{params[:recipient_tax_number]}\n"
  html << "#{indent*2}</td>\n"
  html << "#{indent*2}<td class=\"sender\">\n"
  html << "#{indent*3}#{params[:sender_tax_number]}\n"
  html << "#{indent*2}</td>\n"
  html << "#{indent*1}</tr>\n"
  html << "#{indent*0}</table>\n"
end

#default_credit_note_labelObject



176
177
178
# File 'lib/invoicing/ledger_item/render_html.rb', line 176

def default_credit_note_label
  "Credit Note"
end

#default_date_formatObject



168
169
170
# File 'lib/invoicing/ledger_item/render_html.rb', line 168

def default_date_format
  "%Y-%m-%d"
end

#default_descriptionObject



368
369
370
# File 'lib/invoicing/ledger_item/render_html.rb', line 368

def default_description
  h(get(:description))
end

#default_description_tag(params) ⇒ Object



372
373
374
# File 'lib/invoicing/ledger_item/render_html.rb', line 372

def default_description_tag(params)
  "<p class=\"invoice description\">#{params[:description]}</p>\n"
end

#default_due_date(params) ⇒ Object



355
356
357
358
359
360
361
# File 'lib/invoicing/ledger_item/render_html.rb', line 355

def default_due_date(params)
  if due_date = get(:due_date)
    (params, :due_date, due_date.strftime(params[:date_format]))
  else
    ""
  end
end

#default_due_date_labelObject



209
210
211
# File 'lib/invoicing/ledger_item/render_html.rb', line 209

def default_due_date_label
  "Payment due:"
end

#default_gross_amount_labelObject



253
254
255
# File 'lib/invoicing/ledger_item/render_html.rb', line 253

def default_gross_amount_label
  ""
end

#default_identifier(params) ⇒ Object



327
328
329
# File 'lib/invoicing/ledger_item/render_html.rb', line 327

def default_identifier(params)
  (params, :identifier, get(:identifier))
end

#default_identifier_labelObject



192
193
194
195
# File 'lib/invoicing/ledger_item/render_html.rb', line 192

def default_identifier_label
  label = (factor == BigDecimal('-1')) ? invoke_credit_note_label : invoke_invoice_label
  "#{label} no.:"
end

#default_invoice_labelObject



172
173
174
# File 'lib/invoicing/ledger_item/render_html.rb', line 172

def default_invoice_label
  "Invoice"
end

#default_issue_date(params) ⇒ Object



331
332
333
334
335
336
337
# File 'lib/invoicing/ledger_item/render_html.rb', line 331

def default_issue_date(params)
  if issue_date = get(:issue_date)
    (params, :issue_date, issue_date.strftime(params[:date_format]))
  else
    ""
  end
end

#default_issue_date_labelObject



197
198
199
# File 'lib/invoicing/ledger_item/render_html.rb', line 197

def default_issue_date_label
  "Issue date:"
end

#default_line_description(params) ⇒ Object



399
400
401
# File 'lib/invoicing/ledger_item/render_html.rb', line 399

def default_line_description(params)
  h(line_get(:description))
end

#default_line_description_labelObject



221
222
223
# File 'lib/invoicing/ledger_item/render_html.rb', line 221

def default_line_description_label
  "Description"
end

#default_line_gross_amount(params) ⇒ Object



419
420
421
422
423
424
425
# File 'lib/invoicing/ledger_item/render_html.rb', line 419

def default_line_gross_amount(params)
  if gross_amount = line_get(:gross_amount)
    h(current_line_item.format_currency_value(gross_amount*factor))
  else
    ""
  end
end

#default_line_gross_amount_labelObject



233
234
235
# File 'lib/invoicing/ledger_item/render_html.rb', line 233

def default_line_gross_amount_label
  "Gross price"
end

#default_line_item(params) ⇒ Object



451
452
453
454
455
456
457
458
459
460
# File 'lib/invoicing/ledger_item/render_html.rb', line 451

def default_line_item(params)
  html =  "#{indent*1}<tr>\n"
  html << "#{indent*2}<td class=\"tax-point\">#{   params[:line_tax_point]   }</td>\n" if options[:tax_point_column]
  html << "#{indent*2}<td class=\"quantity\">#{    params[:line_quantity]    }</td>\n" if options[:quantity_column]
  html << "#{indent*2}<td class=\"description\">#{ params[:line_description] }</td>\n" if options[:description_column]
  html << "#{indent*2}<td class=\"net-amount\">#{  params[:line_net_amount]  }</td>\n" if options[:net_amount_column]
  html << "#{indent*2}<td class=\"tax-amount\">#{  params[:line_tax_amount]  }</td>\n" if options[:tax_amount_column]
  html << "#{indent*2}<td class=\"gross-amount\">#{params[:line_gross_amount]}</td>\n" if options[:gross_amount_column]
  html << "#{indent*1}</tr>\n"
end

#default_line_items_header(params) ⇒ Object



376
377
378
379
380
381
382
383
384
385
# File 'lib/invoicing/ledger_item/render_html.rb', line 376

def default_line_items_header(params)
  html =  "#{indent*1}<tr>\n"
  html << "#{indent*2}<th class=\"tax-point\">#{   params[:line_tax_point_label]   }</th>\n" if options[:tax_point_column]
  html << "#{indent*2}<th class=\"quantity\">#{    params[:line_quantity_label]    }</th>\n" if options[:quantity_column]
  html << "#{indent*2}<th class=\"description\">#{ params[:line_description_label] }</th>\n" if options[:description_column]
  html << "#{indent*2}<th class=\"net-amount\">#{  params[:line_net_amount_label]  }</th>\n" if options[:net_amount_column]
  html << "#{indent*2}<th class=\"tax-amount\">#{  params[:line_tax_amount_label]  }</th>\n" if options[:tax_amount_column]
  html << "#{indent*2}<th class=\"gross-amount\">#{params[:line_gross_amount_label]}</th>\n" if options[:gross_amount_column]
  html << "#{indent*1}</tr>\n"
end

#default_line_items_listObject



462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/invoicing/ledger_item/render_html.rb', line 462

def default_line_items_list
  get(:line_items).sorted(:tax_point).map do |line_item|
    @current_line_item = line_item
    invoke_line_item(params_hash(
      :line_tax_point    => [:line_tax_point_label, :date_format],
      :line_quantity     => [:line_quantity_label],
      :line_description  => [:line_description_label],
      :line_net_amount   => [:line_net_amount_label],
      :line_tax_amount   => [:line_tax_amount_label],
      :line_gross_amount => [:line_gross_amount_label]
    ))
  end.join
end

#default_line_items_subtotal(params) ⇒ Object



476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/invoicing/ledger_item/render_html.rb', line 476

def default_line_items_subtotal(params)
  colspan = 0
  colspan += 1 if options[:tax_point_column]
  colspan += 1 if options[:quantity_column]
  colspan += 1 if options[:description_column]
  html =  "#{indent*1}<tr class=\"subtotal\">\n"
  html << "#{indent*2}<th colspan=\"#{colspan}\">#{params[:subtotal_label]}</th>\n"
  html << "#{indent*2}<td class=\"net-amount\">#{params[:net_amount_label]}#{params[:net_amount]}</td>\n" if options[:net_amount_column]
  html << "#{indent*2}<td class=\"tax-amount\">#{params[:tax_amount_label]}#{params[:tax_amount]}</td>\n" if options[:tax_amount_column]
  html << "#{indent*2}<td class=\"gross-amount\"></td>\n" if options[:gross_amount_column]
  html << "#{indent*1}</tr>\n"
end

#default_line_items_table(params) ⇒ Object



503
504
505
506
507
508
# File 'lib/invoicing/ledger_item/render_html.rb', line 503

def default_line_items_table(params)
  html =  "<table class=\"invoice line-items\">\n"
  html << params[:line_items_header] + params[:line_items_list]
  html << params[:line_items_subtotal] if options[:subtotal]
  html << params[:line_items_total] + "</table>\n"
end

#default_line_items_total(params) ⇒ Object



489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/invoicing/ledger_item/render_html.rb', line 489

def default_line_items_total(params)
  colspan = -1
  colspan += 1 if options[:tax_point_column]
  colspan += 1 if options[:quantity_column]
  colspan += 1 if options[:description_column]
  colspan += 1 if options[:net_amount_column]
  colspan += 1 if options[:tax_amount_column]
  colspan += 1 if options[:gross_amount_column]
  html =  "#{indent*1}<tr class=\"total\">\n"
  html << "#{indent*2}<th colspan=\"#{colspan}\">#{params[:total_label]}</th>\n"
  html << "#{indent*2}<td class=\"total-amount\">#{params[:gross_amount_label]}#{params[:total_amount]}</td>\n"
  html << "#{indent*1}</tr>\n"
end

#default_line_net_amount(params) ⇒ Object



403
404
405
406
407
408
409
# File 'lib/invoicing/ledger_item/render_html.rb', line 403

def default_line_net_amount(params)
  if net_amount = line_get(:net_amount)
    h(current_line_item.format_currency_value(net_amount*factor))
  else
    ""
  end
end

#default_line_net_amount_labelObject



225
226
227
# File 'lib/invoicing/ledger_item/render_html.rb', line 225

def default_line_net_amount_label
  "Net price"
end

#default_line_quantity(params) ⇒ Object



395
396
397
# File 'lib/invoicing/ledger_item/render_html.rb', line 395

def default_line_quantity(params)
  h(line_get(:quantity).to_s)
end

#default_line_quantity_labelObject



217
218
219
# File 'lib/invoicing/ledger_item/render_html.rb', line 217

def default_line_quantity_label
  "Quantity"
end

#default_line_tax_amount(params) ⇒ Object



411
412
413
414
415
416
417
# File 'lib/invoicing/ledger_item/render_html.rb', line 411

def default_line_tax_amount(params)
  if tax_amount = line_get(:tax_amount)
    h(current_line_item.format_currency_value(tax_amount*factor))
  else
    ""
  end
end

#default_line_tax_amount_labelObject



229
230
231
# File 'lib/invoicing/ledger_item/render_html.rb', line 229

def default_line_tax_amount_label
  "VAT"
end

#default_line_tax_point(params) ⇒ Object



387
388
389
390
391
392
393
# File 'lib/invoicing/ledger_item/render_html.rb', line 387

def default_line_tax_point(params)
  if tax_point = line_get(:tax_point)
    h(tax_point.strftime(params[:date_format]))
  else
    ""
  end
end

#default_line_tax_point_labelObject



213
214
215
# File 'lib/invoicing/ledger_item/render_html.rb', line 213

def default_line_tax_point_label
  "Tax point"
end

#default_metadata_item(params, key, value) ⇒ Object



319
320
321
322
323
324
325
# File 'lib/invoicing/ledger_item/render_html.rb', line 319

def (params, key, value)
  label = params["#{key}_label".to_sym]
  html =  "#{indent*1}<tr class=\"#{key.to_s.gsub(/_/, '-')}\">\n"
  html << "#{indent*2}<th>#{label}</th>\n"
  html << "#{indent*2}<td>#{h(value)}</td>\n"
  html << "#{indent*1}</tr>\n"
end

#default_metadata_table(params) ⇒ Object



363
364
365
366
# File 'lib/invoicing/ledger_item/render_html.rb', line 363

def (params)
  "<table class=\"invoice metadata\">\n" + params[:identifier] + params[:issue_date] +
    params[:period_start] + params[:period_end] + params[:due_date] + "#{indent*0}</table>\n"
end

#default_net_amount(params) ⇒ Object



427
428
429
430
431
432
433
# File 'lib/invoicing/ledger_item/render_html.rb', line 427

def default_net_amount(params)
  if net_amount = get(:net_amount)
    h(ledger_item.format_currency_value(net_amount*factor))
  else
    ""
  end
end

#default_net_amount_labelObject



245
246
247
# File 'lib/invoicing/ledger_item/render_html.rb', line 245

def default_net_amount_label
  "Net: "
end

#default_optionsObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/invoicing/ledger_item/render_html.rb', line 45

def default_options
  line_items = get(:line_items)
  {
    :tax_point_column    => line_items.map{|i| line_get(:tax_point,  i) }.compact != [],
    :quantity_column     => line_items.map{|i| line_get(:quantity,   i) }.compact != [],
    :description_column  => true,
    :net_amount_column   => true,
    :tax_amount_column   => line_items.map{|i| line_get(:tax_amount, i) }.compact != [],
    :gross_amount_column => false,
    :subtotal            => true
  }
end

#default_page_layout(params) ⇒ Object



510
511
512
513
# File 'lib/invoicing/ledger_item/render_html.rb', line 510

def default_page_layout(params)
  params[:title_tag] + params[:addresses_table] + params[:metadata_table] +
  params[:description_tag] + params[:line_items_table]
end

#default_period_end(params) ⇒ Object



347
348
349
350
351
352
353
# File 'lib/invoicing/ledger_item/render_html.rb', line 347

def default_period_end(params)
  if period_end = get(:period_end)
    (params, :period_end, period_end.strftime(params[:date_format]))
  else
    ""
  end
end

#default_period_end_labelObject



205
206
207
# File 'lib/invoicing/ledger_item/render_html.rb', line 205

def default_period_end_label
  "Period until:"
end

#default_period_start(params) ⇒ Object



339
340
341
342
343
344
345
# File 'lib/invoicing/ledger_item/render_html.rb', line 339

def default_period_start(params)
  if period_start = get(:period_start)
    (params, :period_start, period_start.strftime(params[:date_format]))
  else
    ""
  end
end

#default_period_start_labelObject



201
202
203
# File 'lib/invoicing/ledger_item/render_html.rb', line 201

def default_period_start_label
  "Period from:"
end

#default_recipient_addressObject



282
283
284
# File 'lib/invoicing/ledger_item/render_html.rb', line 282

def default_recipient_address
  invoke_address(get(:recipient_details))
end

#default_recipient_labelObject



180
181
182
# File 'lib/invoicing/ledger_item/render_html.rb', line 180

def default_recipient_label
  "Recipient"
end

#default_recipient_tax_number(params) ⇒ Object



291
292
293
294
# File 'lib/invoicing/ledger_item/render_html.rb', line 291

def default_recipient_tax_number(params)
  recipient_tax_number = get(:recipient_details).symbolize_keys[:tax_number]
  "#{params[:tax_number_label]}<span class=\"tax-number\">#{h(recipient_tax_number)}</span>"
end

#default_sender_addressObject



278
279
280
# File 'lib/invoicing/ledger_item/render_html.rb', line 278

def default_sender_address
  invoke_address(get(:sender_details))
end

#default_sender_labelObject



184
185
186
# File 'lib/invoicing/ledger_item/render_html.rb', line 184

def default_sender_label
  "Sender"
end

#default_sender_tax_number(params) ⇒ Object



286
287
288
289
# File 'lib/invoicing/ledger_item/render_html.rb', line 286

def default_sender_tax_number(params)
  sender_tax_number = get(:sender_details).symbolize_keys[:tax_number]
  "#{params[:tax_number_label]}<span class=\"tax-number\">#{h(sender_tax_number)}</span>"
end

#default_subtotal_labelObject



237
238
239
# File 'lib/invoicing/ledger_item/render_html.rb', line 237

def default_subtotal_label
  "Subtotal"
end

#default_tax_amount(params) ⇒ Object



435
436
437
438
439
440
441
# File 'lib/invoicing/ledger_item/render_html.rb', line 435

def default_tax_amount(params)
  if tax_amount = get(:tax_amount)
    h(ledger_item.format_currency_value(tax_amount*factor))
  else
    ""
  end
end

#default_tax_amount_labelObject



249
250
251
# File 'lib/invoicing/ledger_item/render_html.rb', line 249

def default_tax_amount_label
  "VAT: "
end

#default_tax_number_labelObject



188
189
190
# File 'lib/invoicing/ledger_item/render_html.rb', line 188

def default_tax_number_label
  "VAT number:<br />"
end

#default_titleObject



257
258
259
# File 'lib/invoicing/ledger_item/render_html.rb', line 257

def default_title
  (factor == BigDecimal('-1')) ? invoke_credit_note_label : invoke_invoice_label
end

#default_title_tag(params) ⇒ Object



261
262
263
# File 'lib/invoicing/ledger_item/render_html.rb', line 261

def default_title_tag(params)
  "<h1 class=\"invoice\">#{params[:title]}</h1>\n"
end

#default_total_amount(params) ⇒ Object



443
444
445
446
447
448
449
# File 'lib/invoicing/ledger_item/render_html.rb', line 443

def default_total_amount(params)
  if total_amount = get(:total_amount)
    h(ledger_item.format_currency_value(total_amount*factor))
  else
    ""
  end
end

#default_total_labelObject



241
242
243
# File 'lib/invoicing/ledger_item/render_html.rb', line 241

def default_total_label
  "Total"
end

#get(method_id) ⇒ Object

Returns the value of a (potentially renamed) method on the ledger item



88
89
90
# File 'lib/invoicing/ledger_item/render_html.rb', line 88

def get(method_id)
  ledger_item.send(:ledger_item_class_info).get(ledger_item, method_id)
end

#h(s) ⇒ Object



58
59
60
# File 'lib/invoicing/ledger_item/render_html.rb', line 58

def h(s)
  s.to_s.gsub(/[#{HTML_ESCAPE.keys.join}]/) { |char| HTML_ESCAPE[char] }
end

#indentObject

String for one level of indentation



98
99
100
# File 'lib/invoicing/ledger_item/render_html.rb', line 98

def indent
  '    '
end

#line_get(method_id, line_item = current_line_item) ⇒ Object

Returns the value of a (potentially renamed) method on a line item



93
94
95
# File 'lib/invoicing/ledger_item/render_html.rb', line 93

def line_get(method_id, line_item = current_line_item)
  line_item.send(:line_item_class_info).get(line_item, method_id)
end

#params_hash(*param_names) ⇒ Object

This is quite meta. :)

params_hash(:sender_label, :sender_tax_number => :tax_number_label)
  # => {:sender_label => invoke_sender_label,
  #     :sender_tax_number => invoke_sender_tax_number(params_hash(:tax_number_label))}


107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/invoicing/ledger_item/render_html.rb', line 107

def params_hash(*param_names)
  result = {}
  param_names.flatten!
  options = param_names.extract_options!
  
  param_names.each{|param| result[param.to_sym] = send("invoke_#{param}") }
  
  options.each_pair do |key, value|
    result[key.to_sym] = send("invoke_#{key}", params_hash(value))
  end
  
  result
end