Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_rails_utils/patches/numeric/number_helper.rb

Constant Summary collapse

DEFAULT_PRECISION =
2

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.number_helperObject

Returns A object that extends [ActionView::Helpers::NumberHelper].

Returns:

  • (Object)

    A object that extends [ActionView::Helpers::NumberHelper]



10
11
12
13
14
15
16
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 10

def number_helper
  @number_helper ||= begin
    r = ::Object.new
    r.extend(::ActionView::Helpers::NumberHelper)
    r
  end
end

Instance Method Details

#default_precision_options(options = {}) ⇒ Object



19
20
21
22
23
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 19

def default_precision_options(options = {})
  r = options.dup
  r[:precision] = DEFAULT_PRECISION
  r
end

#number_helperObject

Returns A object that extends [ActionView::Helpers::NumberHelper].

Returns:

  • (Object)

    A object that extends [ActionView::Helpers::NumberHelper]



26
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 26

delegate :number_helper, to: :class

#to_currency(options = {}) ⇒ String

Returns:

  • (String)


29
30
31
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 29

def to_currency(options = {})
  number_helper.number_to_currency(self, default_precision_options(options))
end

#to_human(options = {}) ⇒ String

Returns:

  • (String)


34
35
36
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 34

def to_human(options = {})
  number_helper.number_to_human(self, default_precision_options(options))
end

#to_human_size(options = {}) ⇒ String

Returns:

  • (String)


39
40
41
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 39

def to_human_size(options = {})
  number_helper.number_to_human_size(self, default_precision_options(options))
end

#to_percentage(options = {}) ⇒ String

Returns:

  • (String)


44
45
46
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 44

def to_percentage(options = {})
  number_helper.number_to_percentage(self, default_precision_options(options))
end

#to_phone(options = {}) ⇒ String

Returns:

  • (String)


49
50
51
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 49

def to_phone(options = {})
  number_helper.number_to_phone(self, options)
end

#with_delimiter(options = {}) ⇒ String

Returns:

  • (String)


54
55
56
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 54

def with_delimiter(options = {})
  number_helper.number_with_delimiter(self, options)
end

#with_precision(options = {}) ⇒ String

Returns:

  • (String)


59
60
61
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 59

def with_precision(options = {})
  number_helper.number_with_precision(self, default_precision_options(options))
end