class Hermes::Css::Selector

Public Class Methods

new() click to toggle source
# File lib/hermes/css.rb, line 67
def initialize
  @chain = []
end

Public Instance Methods

dup() click to toggle source
# File lib/hermes/css.rb, line 100
def dup
  s = Selector.new
  s.replace @chain
  s
end
tag(descend, name, sub) { || ... } click to toggle source
# File lib/hermes/css.rb, line 70
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_s() click to toggle source
# File lib/hermes/css.rb, line 105
def to_s
  @chain.map { |c| c.join }.join " "
end

Protected Instance Methods

replace(chain) click to toggle source
# File lib/hermes/css.rb, line 96
def replace chain
  @chain.replace chain
end