Class: Stylish::Selectors

Inherits:
Array
  • Object
show all
Includes:
Formattable
Defined in:
lib/stylish/core.rb

Overview

Selectors objects are simply used to group Selector objects for more convenient storage and serialisation.

Instance Attribute Summary

Attributes included from Formattable

#format

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Selectors

Since a group of Selectors is just a specialised kind of array, all that is done in its initialiser, regardless of arguments, is to set the default serialisation format.



208
209
210
211
# File 'lib/stylish/core.rb', line 208

def initialize(*args)
  accept_format(/^\s*,\s*$/m, ", ")
  super
end

Instance Method Details

#join(symbols = {}, scope = "") ⇒ Object

The join method overrides the superclass’ method in order to always use a specific separator, and so that the scope that the selectors are being used in can be passed through when Rules etc. are serialised.



216
217
218
219
220
# File 'lib/stylish/core.rb', line 216

def join(symbols = {}, scope = "")
  self.inject("") do |ss, s|
    (ss.empty? ? "" : ss + self.format) + s.to_s(symbols, scope)
  end
end

#to_s(symbols = {}, scope = "") ⇒ Object

The to_s method alternative way of calling the join method.



223
224
225
# File 'lib/stylish/core.rb', line 223

def to_s(symbols = {}, scope = "")
  self.join(symbols, scope)
end