Class: Stylish::Selector
- Inherits:
-
Object
- Object
- Stylish::Selector
- Defined in:
- lib/stylish/core.rb
Overview
Selector objects are just string containers, which when serialised are passed the scope in which they are situated. The Selector class is one of Stylish’s most basic units, and are generally used only by internal APIs when constructing Rule objects, rather than by end users (although nothing prevents this; it is merely inconvenient to do so).
Instance Method Summary collapse
-
#initialize(selector) ⇒ Selector
constructor
Selectors are immutable once created; the value of a given Selector must be set when the object is created.
-
#to_s(symbols = {}, scope = "") ⇒ Object
Each Rule possesses one or more Selectors.
Constructor Details
#initialize(selector) ⇒ Selector
Selectors are immutable once created; the value of a given Selector must be set when the object is created.
182 183 184 |
# File 'lib/stylish/core.rb', line 182 def initialize(selector) @selector = selector end |
Instance Method Details
#to_s(symbols = {}, scope = "") ⇒ Object
Each Rule possesses one or more Selectors. Rules are often placed in selector trees, and thus when serialised a Selector must be made aware of the context or scope in which it is being serialised.
Selector.new("p").to_s("body") # => "body p"
The Selector class is also used internally by the Tree::SelectorScope class, to store its scope value.
194 195 196 197 |
# File 'lib/stylish/core.rb', line 194 def to_s(symbols = {}, scope = "") (scope.empty? ? "" : scope + " ") + (@selector.is_a?(String) ? @selector.to_s : @selector.to_s(symbols)) end |