Class: Stylish::Selector

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

Constructor Details

#initialize(selector) ⇒ Selector

Selectors are immutable once created; the value of a given Selector must be set when the object is created.



199
200
201
# File 'lib/stylish/core.rb', line 199

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.



211
212
213
# File 'lib/stylish/core.rb', line 211

def to_s(symbols = {}, scope = "")
  (scope.empty? ? "" : scope + " ") + @selector
end