module HtmlFormat

Public Instance Methods

as_html(**rules) click to toggle source
# File lib/money_extensions/html_format.rb, line 13
def as_html(**rules)
  rules[:html_wrap] = true
  format(**rules).html_safe
end
format(**rules) click to toggle source
Calls superclass method
# File lib/money_extensions/html_format.rb, line 6
def format(**rules)
  html_wrap = rules.delete(:html_wrap)
  return html_wrap(super(**rules)) if html_wrap

  super(**rules)
end

Private Instance Methods

direction_class() click to toggle source
# File lib/money_extensions/html_format.rb, line 24
def direction_class
  if cents > 0
    'positive'
  elsif cents < 0
    'negative'
  else
    'zero'
  end
end
html_wrap(str) click to toggle source
# File lib/money_extensions/html_format.rb, line 20
def html_wrap(str)
  "<span class=\"money #{direction_class}\">#{str}</span>"
end