Class: Talius

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

Overview

A Talius object represents a full CSS selector.

Defined Under Namespace

Classes: Node, Rule

Constant Summary collapse

VERSION =

version ‘0.6’

'0.6'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(p_raw) ⇒ Talius

Initialize a new Talius object. Takes a raw CSS selector string as the single param.

raw = 'a[href]'
selector = Talius.new(raw)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Attribute Details

#rawObject (readonly)

The original string used to the create the selector object.

raw = 'a[href]'
selector = Talius.new(raw)
selector.raw # => "a[href]"


55
56
57
# File 'lib/talius.rb', line 55

def raw
  @raw
end

#rulesObject (readonly)

An array of rule objects.



13
14
15
# File 'lib/talius.rb', line 13

def rules
  @rules
end

Instance Method Details

#denormalize(raw) ⇒ Object

Used by Talius::Rule to rebuild a string that has placeholders in it. This method is not useful for any purpose beyond that.



68
69
70
# File 'lib/talius.rb', line 68

def denormalize(raw)
	return reslash(requote(raw))
end