Class: Vangogh::Number

Inherits:
Object
  • Object
show all
Defined in:
lib/vangogh/number.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Number

Returns a new instance of Number.



6
7
8
9
10
11
12
# File 'lib/vangogh/number.rb', line 6

def initialize(value)
  if value.is_a?(String)
    @value = value.strip.to_f
  else
    @value = value
  end
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/vangogh/number.rb', line 4

def value
  @value
end

Instance Method Details

#abbreviateObject



18
19
20
# File 'lib/vangogh/number.rb', line 18

def abbreviate
  SI.convert(abstract).sub(/0+([a-z])/i, "\\1").sub(/\.([a-z])/i, "\\1")
end

#abstractObject



14
15
16
# File 'lib/vangogh/number.rb', line 14

def abstract
  value.round(1 - abstracted_digits)
end