Module: Dossier::Formatter

Extended by:
Formatter
Includes:
ActionView::Helpers::NumberHelper, ActiveSupport::Inflector
Included in:
Formatter
Defined in:
lib/dossier/formatter.rb

Defined Under Namespace

Classes: UrlFormatter

Instance Method Summary collapse

Instance Method Details

#commafy_number(value, precision = nil) ⇒ Object



15
16
17
18
19
# File 'lib/dossier/formatter.rb', line 15

def commafy_number(value, precision = nil)
  whole, fraction = value.to_s.split('.')
  fraction = "%.#{precision}d" % (BigDecimal.new("0.#{fraction}").round(precision) * 10**precision).to_i if precision
  [whole.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,"), fraction].compact.join('.')
end

#number_to_currency_from_cents(value) ⇒ Object



7
8
9
# File 'lib/dossier/formatter.rb', line 7

def number_to_currency_from_cents(value)
  number_to_currency(value /= 100.0)
end

#number_to_dollars(value) ⇒ Object



11
12
13
# File 'lib/dossier/formatter.rb', line 11

def number_to_dollars(value)
  commafy_number(value, 2).sub(/(\d)/, '$\1')
end

#report_name(report) ⇒ Object



25
26
27
# File 'lib/dossier/formatter.rb', line 25

def report_name(report)
  titleize("#{report.report_name.split('/').last} Report")
end

#url_formatterObject



21
22
23
# File 'lib/dossier/formatter.rb', line 21

def url_formatter
  @url_formatter ||= UrlFormatter.new
end