Class: Phi::Losophy::Page::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/phi/losophy/page/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_parenthesesObject

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

#parentObject (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

#anchorObject



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

Returns:

  • (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