Class: Phi::Losophy::Page::Node
- Inherits:
-
Object
- Object
- Phi::Losophy::Page::Node
- Defined in:
- lib/phi/losophy/page/node.rb
Instance Attribute Summary collapse
-
#in_parentheses ⇒ Object
Returns the value of attribute in_parentheses.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #anchor ⇒ Object
-
#initialize(parent) ⇒ Node
constructor
A new instance of Node.
- #out_of_parentheses? ⇒ Boolean
- #text(node) ⇒ Object
Constructor Details
#initialize(parent) ⇒ Node
Returns a new instance of Node.
8 9 10 |
# File 'lib/phi/losophy/page/node.rb', line 8 def initialize(parent) @parent = parent end |
Instance Attribute Details
#in_parentheses ⇒ Object
Returns the value of attribute in_parentheses.
6 7 8 |
# File 'lib/phi/losophy/page/node.rb', line 6 def in_parentheses @in_parentheses end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/phi/losophy/page/node.rb', line 5 def parent @parent end |
Instance Method Details
#anchor ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/phi/losophy/page/node.rb', line 12 def anchor parent.children.each do |child| if child.name == 'text' text(child) elsif child.name == 'a' && out_of_parentheses? return child end end end |
#out_of_parentheses? ⇒ Boolean
32 33 34 |
# File 'lib/phi/losophy/page/node.rb', line 32 def out_of_parentheses? !in_parentheses end |
#text(node) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/phi/losophy/page/node.rb', line 22 def text(node) node.text.split('').each { |c| if c == '(' self.in_parentheses = true elsif c == ')' self.in_parentheses = false end } end |