Class: Sass::Constant::Number
- Inherits:
-
Literal
show all
- Defined in:
- lib/gems/haml-2.0.4/lib/sass/constant/number.rb
Overview
Constant Summary
Constants inherited
from Literal
Literal::COLOR, Literal::NUMBER
Instance Attribute Summary collapse
Attributes inherited from Literal
#value
Instance Method Summary
collapse
Methods inherited from Literal
#concat, #initialize, parse, #perform
Instance Attribute Details
Returns the value of attribute unit.
6
7
8
|
# File 'lib/gems/haml-2.0.4/lib/sass/constant/number.rb', line 6
def unit
@unit
end
|
Instance Method Details
#div(other) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/gems/haml-2.0.4/lib/sass/constant/number.rb', line 42
def div(other)
if other.is_a? Number
operate(other, :/)
else
raise NoMethodError.new(nil, :div)
end
end
|
#minus(other) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/gems/haml-2.0.4/lib/sass/constant/number.rb', line 24
def minus(other)
if other.is_a? Number
operate(other, :-)
else
raise NoMethodError.new(nil, :minus)
end
end
|
#mod(other) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/gems/haml-2.0.4/lib/sass/constant/number.rb', line 50
def mod(other)
if other.is_a? Number
operate(other, :%)
else
raise NoMethodError.new(nil, :mod)
end
end
|
#parse(value) ⇒ Object
8
9
10
11
12
|
# File 'lib/gems/haml-2.0.4/lib/sass/constant/number.rb', line 8
def parse(value)
first, second, unit = value.scan(Literal::NUMBER)[0]
@value = first.empty? ? second.to_i : "#{first}#{second}".to_f
@unit = unit.empty? ? nil : unit
end
|
#plus(other) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/gems/haml-2.0.4/lib/sass/constant/number.rb', line 14
def plus(other)
if other.is_a? Number
operate(other, :+)
elsif other.is_a? Color
other.plus(self)
else
Sass::Constant::String.from_value(self.to_s + other.to_s)
end
end
|
#times(other) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/gems/haml-2.0.4/lib/sass/constant/number.rb', line 32
def times(other)
if other.is_a? Number
operate(other, :*)
elsif other.is_a? Color
other.times(self)
else
raise NoMethodError.new(nil, :times)
end
end
|
58
59
60
61
62
|
# File 'lib/gems/haml-2.0.4/lib/sass/constant/number.rb', line 58
def to_s
value = @value
value = value.to_i if value % 1 == 0.0
"#{value}#{@unit}"
end
|