Class: Talius::Node
- Inherits:
-
Object
- Object
- Talius::Node
- Defined in:
- lib/talius.rb
Overview
Base class for Talius::Node::Tag and Talius::Node::Att.
Defined Under Namespace
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the tag or attribute.
-
#namespace ⇒ Object
readonly
The node’s namespace.
Instance Method Summary collapse
-
#full_name ⇒ Object
Returns the namespace (if there is one) and the name of the node.
-
#initialize(raw) ⇒ Node
constructor
Initializes a new node.
-
#inspect ⇒ Object
Returns the stringification of the hash returned by
to_h
. -
#to_h ⇒ Object
Returns a hash of the name and namespace (if there is a namespace).
-
#to_s ⇒ Object
Returns the results of
full_name
.
Constructor Details
#initialize(raw) ⇒ Node
Initializes a new node. Accepts the string from the selector. Generally, you won’t have to instantiate a Talius::Node object yourself.
533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
# 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 |
Instance Attribute Details
#name ⇒ Object (readonly)
579 580 581 |
# File 'lib/talius.rb', line 579 def name @name end |
#namespace ⇒ Object (readonly)
563 564 565 |
# File 'lib/talius.rb', line 563 def namespace @namespace end |
Instance Method Details
#full_name ⇒ Object
596 597 598 599 600 601 602 |
# File 'lib/talius.rb', line 596 def full_name if @namespace return @namespace + '|' + @name else return @name end end |
#inspect ⇒ Object
656 657 658 |
# File 'lib/talius.rb', line 656 def inspect return to_h.inspect end |
#to_h ⇒ Object
631 632 633 634 635 636 637 638 639 640 641 |
# 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 ⇒ Object
Returns the results of full_name
.
613 614 615 |
# File 'lib/talius.rb', line 613 def to_s return full_name end |