Class: Stylish::Length

Inherits:
Object
  • Object
show all
Defined in:
lib/stylish/numeric.rb

Constant Summary collapse

UNITS =
[
# Relative length units
"em", "ex", "px",
# Absolute length units
"in", "cm", "mm", "pt", "pc"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Length

Returns a new instance of Length.



34
35
36
37
# File 'lib/stylish/numeric.rb', line 34

def initialize(value)
  self.unit  = value.match(/(#{UNITS * "|"})$/)[0]
  self.value = value[0..-3]
end

Instance Attribute Details

#unitObject

Returns the value of attribute unit.



32
33
34
# File 'lib/stylish/numeric.rb', line 32

def unit
  @unit
end

#valueObject

Returns the value of attribute value.



32
33
34
# File 'lib/stylish/numeric.rb', line 32

def value
  @value
end

Instance Method Details

#to_s(symbols = {}, scope = "") ⇒ Object



53
54
55
# File 'lib/stylish/numeric.rb', line 53

def to_s(symbols = {}, scope = "")
  self.value.to_s + self.unit
end