Class: CSSensible::EmValue

Inherits:
Numeric
  • Object
show all
Includes:
Comparable
Defined in:
lib/cssensible/em_value.rb

Constant Summary collapse

MAX_DECIMAL_PLACES =

The maximum number of decimal places allowed in an em-value.

3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ EmValue

Returns a new em-value based on the value passed to new.



18
19
20
# File 'lib/cssensible/em_value.rb', line 18

def initialize(value)
  @value = value.to_f
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



11
12
13
# File 'lib/cssensible/em_value.rb', line 11

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



13
14
15
# File 'lib/cssensible/em_value.rb', line 13

def <=>(other)
  @value <=> other.value
end

#to_fObject



32
33
34
# File 'lib/cssensible/em_value.rb', line 32

def to_f
  @value.to_f
end

#to_sObject



36
37
38
# File 'lib/cssensible/em_value.rb', line 36

def to_s
  @value.to_s
end

#usable?Boolean

:call-seq:

usable? -> true or false

Returns true if the em-value has no more decimal places than specified in MAX_DECIMAL_PLACES.

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/cssensible/em_value.rb', line 27

def usable?
  # shift decimal point and check if no decimal places remain
  @value.shift_decimal_point(MAX_DECIMAL_PLACES).decimal_places.zero?
end