Class: Sass::Selector::Simple
- Inherits:
- Object
- Object
- Sass::Selector::Simple
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/simple.rb
Overview
The abstract superclass for simple selectors (that is, those that don’t compose multiple selectors).
Instance Attribute Summary (collapse)
- - (String?) filename
The name of the file in which this selector was declared, or
nil
if it was not declared in a file (e.g. on stdin). - - (Fixnum) line
The line of the Sass template on which this selector was declared.
Instance Method Summary (collapse)
- - (Boolean) eql?(other) (also: #==)
Checks equality between this and another object.
- - (String) equality_key protected
Returns the key used for testing whether selectors are equal.
- - (Fixnum) hash
Returns a hash code for this selector object.
- - (String) inspect
- - (String) to_s(opts = {})
Returns the selector string.
- - (Array<Simple>?) unify(sels)
Unifies this selector with a SimpleSequence‘s members array, returning another
SimpleSequence
members array that matches both this selector and the input selector. - - (Array(String or nil, Boolean)) unify_namespaces(ns1, ns2) protected
Unifies two namespaces, returning a namespace that works for both of them if possible.
Instance Attribute Details
- (String?) filename
The name of the file in which this selector was declared, or nil
if it was not declared in a file (e.g. on stdin).
15 16 17 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/simple.rb', line 15
def filename
@filename
end |
- (Fixnum) line
The line of the Sass template on which this selector was declared.
9 10 11 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/simple.rb', line 9
def line
@line
end |
Instance Method Details
- (Boolean) eql?(other) Also known as: ==
Checks equality between this and another object.
By default, this is based on the value of #to_a, so if that contains information irrelevant to the identity of the selector, this should be overridden.
52 53 54 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/simple.rb', line 52
def eql?(other)
other.class == self.class && other.hash == hash && other.equality_key == equality_key
end |
- (String) equality_key (protected)
Returns the key used for testing whether selectors are equal.
This is a cached version of #to_s.
91 92 93 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/simple.rb', line 91
def equality_key
@equality_key ||= to_s
end |
- (Fixnum) hash
Returns a hash code for this selector object.
By default, this is based on the value of #to_a, so if that contains information irrelevant to the identity of the selector, this should be overridden.
40 41 42 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/simple.rb', line 40
def hash
@_hash ||= equality_key.hash
end |
- (String) inspect
20 21 22 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/simple.rb', line 20
def inspect
to_s
end |
- (String) to_s(opts = {})
Returns the selector string.
29 30 31 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/simple.rb', line 29
def to_s(opts = {})
Sass::Util.abstract(self)
end |
- (Array<Simple>?) unify(sels)
Unifies this selector with a Sass::Selector::SimpleSequence‘s members array, returning another SimpleSequence
members array that matches both this selector and the input selector.
By default, this just appends this selector to the end of the array (or returns the original array if this selector already exists in it).
74 75 76 77 78 79 80 81 82 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/simple.rb', line 74
def unify(sels)
return sels if sels.any? {|sel2| eql?(sel2)}
sels_with_ix = Sass::Util.enum_with_index(sels)
if !is_a?(Pseudo) || (sels.last.is_a?(Pseudo) && sels.last.type == :element)
_, i = sels_with_ix.find {|sel, _| sel.is_a?(Pseudo)}
end
return sels + [self] unless i
sels[0...i] + [self] + sels[i..-1]
end |
- (Array(String or nil, Boolean)) unify_namespaces(ns1, ns2) (protected)
Unifies two namespaces, returning a namespace that works for both of them if possible.
108 109 110 111 112 113 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/simple.rb', line 108
def unify_namespaces(ns1, ns2)
return nil, false unless ns1 == ns2 || ns1.nil? || ns1 == '*' || ns2.nil? || ns2 == '*'
return ns2, true if ns1 == '*'
return ns1, true if ns2 == '*'
[ns1 || ns2, true]
end |