Class: Hermeneutics::Css::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/hermeneutics/css.rb

Instance Method Summary collapse

Constructor Details

#initializeSelector

Returns a new instance of Selector.



89
90
91
# File 'lib/hermeneutics/css.rb', line 89

def initialize
  @chain = []
end

Instance Method Details

#dupObject



122
123
124
125
126
# File 'lib/hermeneutics/css.rb', line 122

def dup
  s = Selector.new
  s.replace @chain
  s
end

#tag(descend, name, sub) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/hermeneutics/css.rb', line 92

def tag descend, name, sub
  descend and @chain.empty? and
    raise "Descendor without previous tag: #{descend} #{name}#{sub}."
  c = []
  c.push case descend
    when ">", :child   then "> "
    when "+", :sibling then "+ "
    when nil           then
    else
      raise "Unknown descendor: #{descend}"
  end
  c.push name if name == "*" or Html::TAGS[ name]
  if sub then
    sub =~ /\A(?:
              [:.#]([a-z_0-9-]+)|
              \[([a-z0-9-]+)([~|]?=)(.*)\]
            )*\z/ix or
      raise "Improper tag specification: #{name}#{sub}."
    c.push sub
  end
  @chain.push c
  yield
ensure
  @chain.pop
end

#to_sObject



127
128
129
# File 'lib/hermeneutics/css.rb', line 127

def to_s
  @chain.map { |c| c.join }.join " "
end