Class: Dozuki::Node
- Inherits:
-
Object
show all
- Defined in:
- lib/dozuki/node.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(nokogiri_node) ⇒ Node
Returns a new instance of Node.
6
7
8
|
# File 'lib/dozuki/node.rb', line 6
def initialize(nokogiri_node)
self.nokogiri_node = nokogiri_node
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
10
11
12
|
# File 'lib/dozuki/node.rb', line 10
def method_missing(method, *args, &blk)
nokogiri_node.send(method, *args, &blk)
end
|
Instance Attribute Details
#nokogiri_node ⇒ Object
Returns the value of attribute nokogiri_node.
4
5
6
|
# File 'lib/dozuki/node.rb', line 4
def nokogiri_node
@nokogiri_node
end
|
Instance Method Details
#boolean(xpath) ⇒ Object
39
40
41
|
# File 'lib/dozuki/node.rb', line 39
def boolean(xpath)
Parsers::Boolean.parse(get_first_node(xpath))
end
|
#date(xpath) ⇒ Object
35
36
37
|
# File 'lib/dozuki/node.rb', line 35
def date(xpath)
Parsers::Date.parse(get_first_node(xpath))
end
|
#each(xpath, &blk) ⇒ Object
18
19
20
21
|
# File 'lib/dozuki/node.rb', line 18
def each(xpath, &blk)
collection = NodeCollection.new(nokogiri_node.xpath(xpath))
block_given? ? collection.as_node(&blk) : collection
end
|
#exists?(xpath) ⇒ Boolean
49
50
51
|
# File 'lib/dozuki/node.rb', line 49
def exists?(xpath)
!nokogiri_node.xpath(xpath).empty?
end
|
#float(xpath) ⇒ Object
31
32
33
|
# File 'lib/dozuki/node.rb', line 31
def float(xpath)
Parsers::Float.parse(get_first_node(xpath))
end
|
#get(xpath) {|node| ... } ⇒ Object
43
44
45
46
47
|
# File 'lib/dozuki/node.rb', line 43
def get(xpath)
node = Node.new(get_first_node(xpath))
yield node if block_given?
node
end
|
#int(xpath) ⇒ Object
27
28
29
|
# File 'lib/dozuki/node.rb', line 27
def int(xpath)
Parsers::Integer.parse(get_first_node(xpath))
end
|
#respond_to?(method) ⇒ Boolean
14
15
16
|
# File 'lib/dozuki/node.rb', line 14
def respond_to?(method)
nokogiri_node.respond_to?(method) ? true : super
end
|
#string(xpath) ⇒ Object
23
24
25
|
# File 'lib/dozuki/node.rb', line 23
def string(xpath)
Parsers::String.parse(get_first_node(xpath))
end
|