Class: CssCompare::CSS::Component::PageSelector
- Defined in:
- lib/css_compare/css/component/page_selector.rb
Overview
Represents @page directive’s page selector (‘:right`, `LandscapeTable`, `CompanyLetterHead:first`) combined with the page body, that can contain a list of declarations and a list of page margin boxes.
The declarations not assigned to any margin symbol will be automatically grouped under the global margin symbol.
Constant Summary collapse
- GLOBAL_MARGIN_SYMBOL =
The global margin symbol.
'@all'.freeze
Instance Attribute Summary collapse
-
#margin_boxes ⇒ Hash{String => MarginBox}
The margin box directives containing the declarations.
-
#value ⇒ String
The value of this page selector.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Checks, whether two page selectors are equal.
-
#deep_copy(value = @value) ⇒ PageSelector
Creates a deep copy of this page selector.
-
#initialize(value, children, conditions) ⇒ PageSelector
constructor
A new instance of PageSelector.
-
#merge(other) ⇒ Void
Merges this page selector with another one.
-
#to_json ⇒ Hash
Creates the JSON representation of this page selector.
Methods inherited from Base
Constructor Details
#initialize(value, children, conditions) ⇒ PageSelector
Returns a new instance of PageSelector.
32 33 34 35 36 |
# File 'lib/css_compare/css/component/page_selector.rb', line 32 def initialize(value, children, conditions) @value = value @margin_boxes = {} process_margin_boxes(children, conditions) end |
Instance Attribute Details
#margin_boxes ⇒ Hash{String => MarginBox}
The margin box directives containing the declarations.
24 25 26 |
# File 'lib/css_compare/css/component/page_selector.rb', line 24 def margin_boxes @margin_boxes end |
#value ⇒ String
The value of this page selector
18 19 20 |
# File 'lib/css_compare/css/component/page_selector.rb', line 18 def value @value end |
Instance Method Details
#==(other) ⇒ Boolean
Checks, whether two page selectors are equal.
Two page selectors are equal only if both have declared the same margin boxes and they are also equal.
47 48 49 |
# File 'lib/css_compare/css/component/page_selector.rb', line 47 def ==(other) super(@margin_boxes, other.margin_boxes) end |
#deep_copy(value = @value) ⇒ PageSelector
Creates a deep copy of this page selector.
66 67 68 69 70 71 72 73 |
# File 'lib/css_compare/css/component/page_selector.rb', line 66 def deep_copy(value = @value) copy = dup copy.value = value copy.margin_boxes = @margin_boxes.inject({}) do |result, (k, v)| result.update(k => v.deep_copy) end copy end |
#merge(other) ⇒ Void
Merges this page selector with another one.
55 56 57 58 59 |
# File 'lib/css_compare/css/component/page_selector.rb', line 55 def merge(other) other.margin_boxes.each do |_, prop| add_margin_box(prop, true) end end |
#to_json ⇒ Hash
Creates the JSON representation of this page selector.
78 79 80 81 82 83 84 |
# File 'lib/css_compare/css/component/page_selector.rb', line 78 def to_json json = { :selector => @value, :margin_boxes => [] } @margin_boxes.inject(json[:margin_boxes]) do |result, (_k, v)| result << v.to_json end json end |