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
27
28
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 26

def number_helper
  self.class.number_helper
end

#to_currency(options = {}) ⇒ String

Returns:

  • (String)


31
32
33
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 31

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

#to_human(options = {}) ⇒ String

Returns:

  • (String)


36
37
38
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 36

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

#to_human_size(options = {}) ⇒ String

Returns:

  • (String)


41
42
43
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 41

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

#to_percentage(options = {}) ⇒ String

Returns:

  • (String)


46
47
48
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 46

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

#to_phone(options = {}) ⇒ String

Returns:

  • (String)


51
52
53
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 51

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

#with_delimiter(options = {}) ⇒ String

Returns:

  • (String)


56
57
58
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 56

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

#with_precision(options = {}) ⇒ String

Returns:

  • (String)


61
62
63
# File 'lib/eac_rails_utils/patches/numeric/number_helper.rb', line 61

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