Class: NumberToLove::LoveNumber

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/number_to_love/love_number.rb

Constant Summary collapse

HUMAN_ACCESSORS =
[:precision, :significant, :units, :strip_insignificant_zeros, :delimiter, :separator, :format]
CUSTOM_ACCESSORS =
[:minimalize]
ALL_ACCESSORS =
HUMAN_ACCESSORS | CUSTOM_ACCESSORS
VERBOSE_UNITS =
{}
ABBREVIATED_DECIMAL_UNITS =
{            
  unit: "",
  # ten:
  #   one: Ten
  #   other: Tens
  # hundred: Hundred
  thousand: "K",
  million: "M",
  billion: "B",
  trillion: "T"
}

Instance Method Summary collapse

Constructor Details

#initialize(val, opts = {}) ⇒ LoveNumber

Returns a new instance of LoveNumber.



29
30
31
32
33
34
35
36
37
# 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

Instance Method Details

#inspectObject



50
51
52
# File 'lib/number_to_love/love_number.rb', line 50

def inspect
  to_s
end

#to_sObject



44
45
46
47
# 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_vObject



39
40
41
# File 'lib/number_to_love/love_number.rb', line 39

def to_v
  @value
end