class NumberToLove::LoveNumber
Constants
- ABBREVIATED_DECIMAL_UNITS
- ALL_ACCESSORS
- CUSTOM_ACCESSORS
- HUMAN_ACCESSORS
- VERBOSE_UNITS
Public Class Methods
new(val, opts={})
click to toggle source
Calls superclass method
# File lib/number_to_love/love_number.rb, line 29 def initialize(val, opts={}) @value = val interpret_options(opts) @units = ABBREVIATED_DECIMAL_UNITS super(@value) end
Public Instance Methods
inspect()
click to toggle source
# File lib/number_to_love/love_number.rb, line 50 def inspect to_s end
to_s()
click to toggle source
# File lib/number_to_love/love_number.rb, line 44 def to_s opts = render_options number_to_human(@value, opts[:number_to_human]) end
to_v()
click to toggle source
# File lib/number_to_love/love_number.rb, line 39 def to_v @value end
Private Instance Methods
interpret_options(opts)
click to toggle source
command sets attr_accessors
# File lib/number_to_love/love_number.rb, line 85 def interpret_options(opts) opts.each_pair do |att, val| a = att.to_sym if ALL_ACCESSORS.include?(a) self.instance_variable_set("@#{a}", val) end end end
render_options()
click to toggle source
returns a Hash to pass along
# File lib/number_to_love/love_number.rb, line 97 def render_options hsh = {} if minval = @minimalize @units = ABBREVIATED_DECIMAL_UNITS @format = "%n%u" @precision = minval @strip_insignificant_zeros = true @delimiter = '' @significant = true end hsh[:number_to_human] = HUMAN_ACCESSORS.inject({}) do |h, att| if val = self.instance_variable_get("@#{att}") h[att] = val end h end return hsh end