Class: Eg::Page

Inherits:
Fit::RowFixture show all
Defined in:
lib/eg/page.rb

Defined Under Namespace

Classes: Row

Constant Summary collapse

@@url =
nil
@@text =
''

Constants inherited from Fit::Fixture

Fit::Fixture::GRAY, Fit::Fixture::GREEN, Fit::Fixture::RED, Fit::Fixture::YELLOW

Instance Attribute Summary

Attributes inherited from Fit::RowFixture

#missing, #results, #surplus

Attributes inherited from Fit::Fixture

#args, #counts, #listener, #summary

Instance Method Summary collapse

Methods inherited from Fit::RowFixture

#do_rows, #initialize

Methods inherited from Fit::ColumnFixture

#check, #do_cell, #do_row, #do_rows, #execute, #reset

Methods inherited from Fit::Fixture

camel, #check, #do_cell, #do_cells, #do_row, #do_rows, #do_table, #do_tables, #error, escape, #exception, #find_class, #fixture_name, #get_args_for_table, #get_linked_fixture_with_args, gray, #ignore, #info, #initialize, #interpret_following_tables, #interpret_tables, label, metadata, #parse, #right, #total_errors, #totals, #wrong

Constructor Details

This class inherits a constructor from Fit::RowFixture

Instance Method Details

#context(url) ⇒ Object



46
47
48
49
50
# File 'lib/eg/page.rb', line 46

def context url
  u = "#{url.scheme}://#{url.host}"
  u += (url.port == 80 ? '' : ":#{url.port}") + '/'
  u
end

#get(url) ⇒ Object

Utility



67
68
69
70
# File 'lib/eg/page.rb', line 67

def get url
  response = Net::HTTP.get_response url
  response.body
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/eg/page.rb', line 28

def link label
  links = Fit::Parse.new @@text, ['a']
  until links.text =~ /^#{label}/
    links = links.more
  end
  links.tag =~ /href\s*=\s*"(.*)"\s*>?/i
  if $1.nil?
    links.tag =~ /href\s*=\s*(.*)\s*>/i
  end
  link = $1
  if link =~ /^(http:)?\/\//
    @@url = URI.parse($1.nil? ? "http:#{link}" : link)
  else
    @@url = URI.parse(context(@@url) + link)
  end
  @@text = open(@@url) {|stream| stream.read}
end

#location(url) ⇒ Object

Actions



19
20
21
22
# File 'lib/eg/page.rb', line 19

def location url
  @@url = URI.parse url
  @@text = open(@@url) {|stream| stream.read}
end

#queryObject

Rows



54
55
56
57
58
59
60
61
62
63
# File 'lib/eg/page.rb', line 54

def query
  tags = ['wiki', 'table', 'tr', 'td']
  rows = Fit::Parse.new(@@text, tags).at(0, 0, 2)
  result = [nil] * rows.size
  0.upto(rows.size - 1) do |i|
    result[i] = Row.new rows
    rows = rows.more
  end
  result
end

#titleObject



24
25
26
# File 'lib/eg/page.rb', line 24

def title
  Fit::Parse.new(@@text, ['title']).text
end