class Talius::Node
Base class for Talius::Node::Tag
and Talius::Node::Att
.
Attributes
name[R]
The name of the tag or attribute. Does not include the namespace.
raw = 'section, mml|dev' selector = Talius.new(raw) selector.rules[0].tags['section'].name # => "section" selector.rules[1].tags['mml|dev'].name # => "dev"
namespace[R]
The node's namespace. If a namespace is not explicitly given in the selector string then this property is nil.
raw = 'section, mml|dev' selector = Talius.new(raw) selector.rules[0].tags['section'].namespace # => nil selector.rules[1].tags['mml|dev'].namespace # => "mml"
Public Class Methods
new(raw)
click to toggle source
Initializes a new node. Accepts the string from the selector. Generally, you won't have to instantiate a Talius::Node
object yourself.
# File lib/talius.rb, line 533 def initialize(raw) tokens = raw.split('|', 2) # if one element if tokens.length == 1 @namespace = nil @name = tokens[0] elsif tokens.length == 2 @namespace = tokens[0] @name = tokens[1] else raise 'node-syntax-error: ' + raw.to_s end end
Public Instance Methods
full_name()
click to toggle source
Returns the namespace (if there is one) and the name of the node. If there is a namespace then the namespace is followed by |.
raw = 'section, mml|dev' selector = Talius.new(raw) selector.rules[0].tags['section'].fullname # => "section" selector.rules[1].tags['mml|dev'].fullname # => "mml|dev"
# File lib/talius.rb, line 596 def full_name if @namespace return @namespace + '|' + @name else return @name end end
inspect()
click to toggle source
Returns the stringification of the hash returned by to_h
.
raw = 'section, mml|dev' selector = Talius.new(raw) selector.rules[0].tags['section'].inspect # => {"name"=>"section"} selector.rules[1].tags['mml|dev'].inspect # => {"name"=>"dev", "namespace"=>"mml"}
# File lib/talius.rb, line 656 def inspect return to_h.inspect end
to_h()
click to toggle source
Returns a hash of the name and namespace (if there is a namespace).
raw = 'section, mml|dev' selector = Talius.new(raw) selector.rules[0].tags['section'].to_h # => {"name"=>"section"} selector.rules[1].tags['mml|dev'].to_h # => {"name"=>"dev", "namespace"=>"mml"}
# File lib/talius.rb, line 631 def to_h rv = {} rv['name'] = @name # namespace if @namespace rv['namespace'] = @namespace end return rv end
to_s()
click to toggle source
Returns the results of full_name
.
# File lib/talius.rb, line 613 def to_s return full_name end