Class: CssCompare::CSS::Component::KeyframesSelector
- Defined in:
- lib/css_compare/css/component/keyframes_selector.rb
Overview
Represents a rule of the @keyframe directive.
Examples:
- from { top: 0; } // also meaning the same as 0%
- 50% { top: 50; }
- to { top: 100; } // also meaning the same as 100%
Instance Attribute Summary collapse
-
#properties ⇒ Hash{String => Property}
readonly
The properties specified at this rule.
-
#value(value = nil) ⇒ String
readonly
Returns the value represented as percentage, even if declared with the well-known keywords.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Checks, whether two keyframes selectors are equal.
-
#add_property(property) ⇒ Void
Adds a new or rewrites an already existing property of this rule’s set of properties.
- #deep_copy(value = @value) ⇒ Object
-
#initialize(node) ⇒ KeyframesSelector
constructor
A new instance of KeyframesSelector.
-
#process_properties(properties) ⇒ Void
Creates and puts te properties into the set of properties of this rule.
-
#to_json ⇒ Hash
Creates the JSON representation of this keyframes selector.
Methods inherited from Base
Constructor Details
#initialize(node) ⇒ KeyframesSelector
Returns a new instance of KeyframesSelector.
23 24 25 26 27 |
# File 'lib/css_compare/css/component/keyframes_selector.rb', line 23 def initialize(node) @value = value(node.resolved_value) @properties = {} process_properties(node.children) end |
Instance Attribute Details
#properties ⇒ Hash{String => Property} (readonly)
The properties specified at this rule.
19 20 21 |
# File 'lib/css_compare/css/component/keyframes_selector.rb', line 19 def properties @properties end |
#value(value = nil) ⇒ String (readonly)
Returns the value represented as percentage, even if declared with the well-known keywords.
14 15 16 |
# File 'lib/css_compare/css/component/keyframes_selector.rb', line 14 def value @value end |
Instance Method Details
#==(other) ⇒ Boolean
Checks, whether two keyframes selectors are equal.
They are equal only if they have declared the same properties and they are also equal.
37 38 39 |
# File 'lib/css_compare/css/component/keyframes_selector.rb', line 37 def ==(other) super(@properties, other.properties) end |
#add_property(property) ⇒ Void
Adds a new or rewrites an already existing property of this rule’s set of properties.
55 56 57 58 59 60 61 62 |
# File 'lib/css_compare/css/component/keyframes_selector.rb', line 55 def add_property(property) name = property.name if @properties[name] @properties[name].merge(property) else @properties[name] = property end end |
#deep_copy(value = @value) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/css_compare/css/component/keyframes_selector.rb', line 64 def deep_copy(value = @value) copy = dup copy.value = value copy.properties = @properties.inject({}) do |result, (k, v)| result.update(k => v.deep_copy) end end |
#process_properties(properties) ⇒ Void
Creates and puts te properties into the set of properties of this rule.
86 87 88 89 90 |
# File 'lib/css_compare/css/component/keyframes_selector.rb', line 86 def process_properties(properties) properties.each do |prop| add_property(Property.new(prop, ['no condition'])) if prop.is_a?(Sass::Tree::PropNode) end end |
#to_json ⇒ Hash
Creates the JSON representation of this keyframes selector.
76 77 78 79 80 |
# File 'lib/css_compare/css/component/keyframes_selector.rb', line 76 def to_json @properties.inject({}) do |result, (name, prop)| result.update(name.to_sym => prop.to_json) end end |