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.



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

#childrenObject



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

def children
  @elm.children
end

#eachObject



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

#lengthObject



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

def length
  @elm.size
end

#rawObject



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

def raw
  @elm
end

#sizeObject



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

def size
  @elm.size
end

#textObject



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

def text
  @elm.text
end

#to_sObject



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

def to_s
  @elm.to_s
end