Class: Browser::CSS::Unit
Constant Summary collapse
- COMPATIBLE =
%i[in pt mm cm px pc]
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #+@ ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #/(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #===(other) ⇒ Object
- #coerce(other) ⇒ Object
- #hash ⇒ Object
-
#initialize(number, type) ⇒ Unit
constructor
A new instance of Unit.
- #to_f ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object (also: #to_str, #inspect)
- #to_u ⇒ Object
Constructor Details
permalink #initialize(number, type) ⇒ Unit
Returns a new instance of Unit.
8 9 10 11 |
# File 'opal/browser/css/unit.rb', line 8 def initialize(number, type) @number = number @type = type end |
Instance Attribute Details
Instance Method Details
permalink #*(other) ⇒ Object
[View source]
61 62 63 64 65 66 67 68 69 70 71 |
# File 'opal/browser/css/unit.rb', line 61 def *(other) return Unit.new(@number * other, @type) unless Unit === other if @type == other.type Unit.new(@number * other.to_f, @type) elsif compatible?(self) and compatible?(other) Unit.new(@number * convert(other, @type), @type) else raise ArgumentError, "#{other.type} isn't compatible with #{@type}" end end |
permalink #+(other) ⇒ Object
[View source]
37 38 39 40 41 42 43 44 45 46 47 |
# File 'opal/browser/css/unit.rb', line 37 def +(other) return Unit.new(@number + other, @type) unless Unit === other if @type == other.type Unit.new(@number + other.to_f, @type) elsif compatible?(self) and compatible?(other) Unit.new(@number + convert(other, @type), @type) else raise ArgumentError, "#{other.type} isn't compatible with #{@type}" end end |
permalink #+@ ⇒ Object
[View source]
89 90 91 |
# File 'opal/browser/css/unit.rb', line 89 def +@ Unit.new(@number, @type) end |
permalink #-(other) ⇒ Object
[View source]
49 50 51 52 53 54 55 56 57 58 59 |
# File 'opal/browser/css/unit.rb', line 49 def -(other) return Unit.new(@number - other, @type) unless Unit === other if @type == other.type Unit.new(@number - other.to_f, @type) elsif compatible?(self) and compatible?(other) Unit.new(@number - convert(other, @type), @type) else raise ArgumentError, "#{other.type} isn't compatible with #{@type}" end end |
permalink #-@ ⇒ Object
[View source]
85 86 87 |
# File 'opal/browser/css/unit.rb', line 85 def -@ Unit.new(@number * -1, @type) end |
permalink #/(other) ⇒ Object
[View source]
73 74 75 76 77 78 79 80 81 82 83 |
# File 'opal/browser/css/unit.rb', line 73 def /(other) return Unit.new(@number / other, @type) unless Unit === other if @type == other.type Unit.new(@number / other.to_f, @type) elsif compatible?(self) and compatible?(other) Unit.new(@number / convert(other, @type), @type) else raise ArgumentError, "#{other.type} isn't compatible with #{@type}" end end |
permalink #==(other) ⇒ Object Also known as: eql?
[View source]
17 18 19 |
# File 'opal/browser/css/unit.rb', line 17 def ==(other) @number == convert(other, @type) end |
permalink #===(other) ⇒ Object
[View source]
21 22 23 |
# File 'opal/browser/css/unit.rb', line 21 def ===(other) @type == other.type && @number == other.to_f end |
permalink #coerce(other) ⇒ Object
[View source]
13 14 15 |
# File 'opal/browser/css/unit.rb', line 13 def coerce(other) return self, other end |
permalink #hash ⇒ Object
[View source]
27 28 29 |
# File 'opal/browser/css/unit.rb', line 27 def hash [@number, @type].hash end |
permalink #to_f ⇒ Object
[View source]
97 98 99 |
# File 'opal/browser/css/unit.rb', line 97 def to_f @number.to_f end |
permalink #to_i ⇒ Object
[View source]
93 94 95 |
# File 'opal/browser/css/unit.rb', line 93 def to_i @number.to_i end |
permalink #to_s ⇒ Object Also known as: to_str, inspect
[View source]
105 106 107 |
# File 'opal/browser/css/unit.rb', line 105 def to_s "#{@number}#{@type}" end |
permalink #to_u ⇒ Object
[View source]
101 102 103 |
# File 'opal/browser/css/unit.rb', line 101 def to_u self end |