Module: HumanNumber::Rails::Helpers

Defined in:
lib/human_number/rails/helpers.rb

Overview

Rails view helpers for human-readable number and currency formatting.

These helpers provide convenient access to HumanNumber functionality within Rails views and controllers with Rails-friendly parameter handling.

Instance Method Summary collapse

Instance Method Details

#currency(number, currency_code:, locale: I18n.locale, **options) ⇒ Object

Rails helper for formatting currency amounts with standard precision.

Examples:

Basic usage in views

<%= currency(1234.56, currency_code: 'USD') %>    #=> "$1,234.56"
<%= currency(50000, currency_code: 'KRW') %>      #=> "50,000원"

Parameters:

  • number (Numeric) —

    The amount to format

  • currency_code (String) —

    ISO 4217 currency code (e.g., 'USD', 'EUR')

  • locale (Symbol, String, nil) (defaults to: I18n.locale) —

    Display locale (default: current I18n locale)

  • options (Hash) —

    Additional formatting options

See Also:



37
38
39
# File 'lib/human_number/rails/helpers.rb', line 37

def currency(number, currency_code:, locale: I18n.locale, **options)
  HumanNumber.currency(number, currency_code:, locale:, **options)
end

#human_currency(number, currency_code:, locale: I18n.locale, **options) ⇒ Object

Rails helper for formatting currency amounts with intelligent abbreviations.

Examples:

Basic usage in views

<%= human_currency(1234567, currency_code: 'USD') %>      #=> "$1.2M"
<%= human_currency(50000, currency_code: 'KRW') %>        #=> "5만원"

Parameters:

  • number (Numeric) —

    The amount to format

  • currency_code (String) —

    ISO 4217 currency code (e.g., 'USD', 'EUR')

  • locale (Symbol, String, nil) (defaults to: I18n.locale) —

    Locale for formatting (default: current I18n locale)

  • options (Hash) —

    Additional formatting options

See Also:



53
54
55
# File 'lib/human_number/rails/helpers.rb', line 53

def human_currency(number, currency_code:, locale: I18n.locale, **options)
  HumanNumber.human_currency(number, currency_code:, locale:, **options)
end

#human_number(number, locale: I18n.locale, **options) ⇒ Object

Rails helper for formatting numbers with intelligent abbreviations.

Examples:

Basic usage in views

<%= human_number(1234567) %>            #=> "1.2M"
<%= human_number(50000, locale: :ko) %> #=> "5만"

Parameters:

  • number (Numeric) —

    The number to format

  • locale (Symbol, String, nil) (defaults to: I18n.locale) —

    The locale for formatting (default: current I18n locale)

  • options (Hash) —

    Additional formatting options

See Also:



21
22
23
# File 'lib/human_number/rails/helpers.rb', line 21

def human_number(number, locale: I18n.locale, **options)
  HumanNumber.human_number(number, locale:, **options)
end