Class: WebInspector::Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/web_inspector/inspector.rb

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ Inspector

Returns a new instance of Inspector.



6
7
8
9
# File 'lib/web_inspector/inspector.rb', line 6

def initialize(page)
  @page = page
  @meta = WebInspector::Meta.new(page).meta
end

Instance Method Details

#descriptionObject



15
16
17
# File 'lib/web_inspector/inspector.rb', line 15

def description
  @meta['description'] || snippet
end

#imagesObject



31
32
33
34
35
36
37
# File 'lib/web_inspector/inspector.rb', line 31

def images
  images = []
  @page.css("img").each do |img|
    images.push((img[:src].to_s.start_with? @url.to_s) ? img[:src] : URI.join(url, img[:src]).to_s) if (img and img[:src])
  end
  return images
end


23
24
25
26
27
28
29
# File 'lib/web_inspector/inspector.rb', line 23

def links
  links = []
  @page.css("a").each do |a|
    links.push((a[:href].to_s.start_with? @url.to_s) ? a[:href] : URI.join(@url, a[:href]).to_s) if (a and a[:href])
  end
  return links
end

#metaObject



19
20
21
# File 'lib/web_inspector/inspector.rb', line 19

def meta
  @meta
end

#titleObject



11
12
13
# File 'lib/web_inspector/inspector.rb', line 11

def title
  @page.css('title').inner_text.strip rescue nil
end