Class: CssCompare::CSS::Component::KeyframesSelector

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Base

#equals?

Constructor Details

#initialize(node) ⇒ KeyframesSelector

Returns a new instance of KeyframesSelector.

Parameters:

  • node (Sass::Tree::KeyframeRuleNode)

    a rule node of the @keyframe directive.



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

#propertiesHash{String => Property} (readonly)

The properties specified at this rule.

Returns:



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.

Returns:

  • (String)

    the value of the rule



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.

Parameters:

Returns:

  • (Boolean)


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.

Returns:

  • (Void)


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.

Returns:

  • (Void)


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_jsonHash

Creates the JSON representation of this keyframes selector.

Returns:

  • (Hash)


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