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.
8 9 10 |
# File 'lib/kueri.rb', line 8 def initialize(elm) @elm = elm end |
Instance Method Details
#[](query) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/kueri.rb', line 12 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
49 50 51 |
# File 'lib/kueri.rb', line 49 def attr(key) @elm.attr(key).to_s end |
#children ⇒ Object
45 46 47 |
# File 'lib/kueri.rb', line 45 def children @elm.children end |
#each ⇒ Object
39 40 41 42 43 |
# File 'lib/kueri.rb', line 39 def each @elm.each do |o| yield E.new(o) end end |
#find(query) ⇒ Object
22 23 24 25 |
# File 'lib/kueri.rb', line 22 def find(query) elm = @elm.css(query) E.new(elm) end |
#length ⇒ Object
31 32 33 |
# File 'lib/kueri.rb', line 31 def length @elm.size end |
#raw ⇒ Object
35 36 37 |
# File 'lib/kueri.rb', line 35 def raw @elm end |
#size ⇒ Object
27 28 29 |
# File 'lib/kueri.rb', line 27 def size @elm.size end |
#text ⇒ Object
53 54 55 |
# File 'lib/kueri.rb', line 53 def text @elm.text end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/kueri.rb', line 57 def to_s @elm.to_s end |