Class: Kueri::E
Instance Method Summary collapse
- #[](query) ⇒ Object
- #attr(key) ⇒ Object
- #children ⇒ Object
- #each ⇒ Object
- #find(query) ⇒ Object
-
#initialize(elm) ⇒ E
constructor
A new instance of E.
- #length ⇒ Object
- #raw ⇒ Object
- #size ⇒ Object
- #text ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(elm) ⇒ E
Returns a new instance of E.
7 8 9 |
# File 'lib/kueri.rb', line 7 def initialize(elm) @elm = elm end |
Instance Method Details
#[](query) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/kueri.rb', line 11 def [](query) if query.is_a? String self.find(query) elsif query.is_a? Fixnum E.new( @elm[query] ) else raise "query should be String or Fixnum" end end |
#attr(key) ⇒ Object
48 49 50 |
# File 'lib/kueri.rb', line 48 def attr(key) @elm.attr(key).to_s end |
#children ⇒ Object
44 45 46 |
# File 'lib/kueri.rb', line 44 def children @elm.children end |
#each ⇒ Object
38 39 40 41 42 |
# File 'lib/kueri.rb', line 38 def each @elm.each do |o| yield E.new(o) end end |
#find(query) ⇒ Object
21 22 23 24 |
# File 'lib/kueri.rb', line 21 def find(query) elm = @elm.css(query) E.new(elm) end |
#length ⇒ Object
30 31 32 |
# File 'lib/kueri.rb', line 30 def length @elm.size end |
#raw ⇒ Object
34 35 36 |
# File 'lib/kueri.rb', line 34 def raw @elm end |
#size ⇒ Object
26 27 28 |
# File 'lib/kueri.rb', line 26 def size @elm.size end |
#text ⇒ Object
52 53 54 |
# File 'lib/kueri.rb', line 52 def text @elm.text end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/kueri.rb', line 56 def to_s @elm.to_s end |