Class: Kueri::E

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/kueri.rb

Instance Method Summary collapse

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

#childrenObject



44
45
46
# File 'lib/kueri.rb', line 44

def children
  @elm.children
end

#eachObject



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

#lengthObject



30
31
32
# File 'lib/kueri.rb', line 30

def length
  @elm.size
end

#rawObject



34
35
36
# File 'lib/kueri.rb', line 34

def raw
  @elm
end

#sizeObject



26
27
28
# File 'lib/kueri.rb', line 26

def size
  @elm.size
end

#textObject



52
53
54
# File 'lib/kueri.rb', line 52

def text
  @elm.text
end

#to_sObject



56
57
58
# File 'lib/kueri.rb', line 56

def to_s
  @elm.to_s
end