class Talius
A Talius
object represents a full CSS selector.
Constants
- VERSION
version '0.6'
Attributes
raw[R]
The original string used to the create the selector object.
raw = 'a[href]' selector = Talius.new(raw) selector.raw # => "a[href]"
rules[R]
An array of rule objects.
Public Class Methods
new(p_raw)
click to toggle source
Initialize a new Talius
object. Takes a raw CSS selector string as the single param.
raw = 'a[href]' selector = Talius.new(raw)
# File lib/talius.rb, line 24 def initialize(p_raw) @raw = p_raw @rules = [] @slashes = {} @quotes = {} @norm = nil # normalize selector string unslash() unquote() @norm.lx.collapse! # split into rules @norm.split(/\s*,\s*/mu).each do |rule_str| @rules.push Talius::Rule.new(self, rule_str) end end
Public Instance Methods
denormalize(raw)
click to toggle source
Used by Talius::Rule
to rebuild a string that has placeholders in it. This method is not useful for any purpose beyond that.
# File lib/talius.rb, line 68 def denormalize(raw) return reslash(requote(raw)) end
Private Instance Methods
requote(raw)
click to toggle source
# File lib/talius.rb, line 83 def requote(raw) return @quotes[raw] || raw end
reslash(rv)
click to toggle source
# File lib/talius.rb, line 94 def reslash(rv) # $tm.hrm # loop through slashed strings @slashes.each do |pattern, val| rv = rv.sub(/#{pattern}/mu, val) end # return return rv end
unquote()
click to toggle source
# File lib/talius.rb, line 113 def unquote() rv = [] # split into slashed and unslashed strings @norm.split(/("[^"]*")/mu).each do |token| if token.match(/\A".*"\z/mu) content = token content = content.sub(/\A"/mu, '') content = content.sub(/"\z/mu, '') ph = LX.randstr() @quotes[ph] = content rv.push ph else rv.push token end end # return new string @norm = rv.join('') end
unslash()
click to toggle source
# File lib/talius.rb, line 141 def unslash() rv = [] # split into slashed and unslashed strings @raw.split(/(\\.)/mu).each do |token| if token.match(/\A\\.\z/mu) ph = LX.randstr() @slashes[ph] = token[1] rv.push ph else rv.push token end end # return new string @norm = rv.join('') end