webpage 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/lib/webpage.rb CHANGED
@@ -14,6 +14,9 @@ class Webpage
14
14
  end
15
15
  @domain = options[:domain]
16
16
  end
17
+ def h1
18
+ @nokogiri.xpath("//h1").text
19
+ end
17
20
  def title
18
21
  @nokogiri.xpath("//title").text
19
22
  end
data/spec/webpage_spec.rb CHANGED
@@ -1,8 +1,10 @@
1
+ # encoding: utf-8
2
+
1
3
  #coding:UTF-8
2
4
  require 'webpage'
3
5
  sample = File.read(File.join(File.dirname(__FILE__),'sample'))
4
6
  sample_uri = 'http://www.hudong.com/wiki/甜菜根'
5
- sample_to_uri = 'http://123.hudong.com/'
7
+ sample_to_uri = 'http://www.hudong.com/'
6
8
  sample_not_to_uri = 'http://1234.hudong.com/'
7
9
  sample_to_host = 'hudong.com'
8
10
  sample_title = '甜菜根_互动百科'
@@ -28,8 +30,8 @@ describe Webpage do
28
30
  it "links should be an array" do
29
31
  page.links.class.should == Array
30
32
  end
31
- it "['h1'].to_a should return Array" do
32
- page['h1'].to_a.class.should == Array
33
+ it "h1 should return String" do
34
+ page.h1.class.should == String
33
35
  end
34
36
 
35
37
  it "[] should return class Nokogiri::XML::NodeSet" do
@@ -41,8 +43,8 @@ describe Webpage do
41
43
  it "nodes_with should return an array with elements Nokogiri::XML::NodeSet" do
42
44
  page.nodes_with('id').class.should == Nokogiri::XML::NodeSet
43
45
  end
44
- it "xpath should return an array with elements Nokogiri::XML::NodeSet" do
45
- page.xpath('//id').class.should == Nokogiri::XML::NodeSet
46
+ it "nokogiri.xpath should return an array with elements Nokogiri::XML::NodeSet" do
47
+ page.nokogiri.xpath('//id').class.should == Nokogiri::XML::NodeSet
46
48
  end
47
49
  it "links' elements should be Webpage::Link" do
48
50
  page.links.each do |link|
@@ -53,7 +55,7 @@ describe Webpage do
53
55
  it "description should be text" do
54
56
  page.description.class.should == String
55
57
  end
56
-
58
+
57
59
  it "keywords should be array" do
58
60
  page.keywords.class.should == Array
59
61
  end
@@ -63,7 +65,7 @@ describe Webpage do
63
65
  keyword.class.should == String
64
66
  end
65
67
  end
66
-
68
+
67
69
  it "link_to? should return bool" do
68
70
  [TrueClass,FalseClass].should include page.link_to?(sample_to_uri).class
69
71
  end
@@ -98,7 +100,7 @@ describe "the instance webpage of #{sample_uri}" do
98
100
  page.nodes_with('id').size.should == 92
99
101
  end
100
102
  it "should has <h1>#{sample_h1}"do
101
- page['h1'].text.should == sample_h1
103
+ page.h1.should == sample_h1
102
104
  end
103
105
  it "should has canonical to #{sample_uri}" do
104
106
  page.canonical.should == sample_uri
@@ -111,7 +113,7 @@ describe "the instance webpage of #{sample_uri}" do
111
113
  it "should not link_to #{sample_not_to_uri}" do
112
114
  page.link_to?(sample_not_to_uri).should be_false
113
115
  end
114
-
116
+
115
117
  it "should has link to " do
116
118
  page.links_to_different_host.any?{|link|link['href']}
117
119
  end
data/webpage.gemspec CHANGED
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{webpage}
3
- s.version = '0.0.9'
3
+ s.version = '0.0.10'
4
4
  s.authors = ["seoaqua"]
5
- s.date = %q{2012-07-29}
5
+ s.date = %q{2013-02-28}
6
6
  s.description = %q{a tool to extract some basic data from a webpage}
7
7
  s.email = %q{seoaqua@qq.com}
8
8
  s.files = `git ls-files`.split("\n")
9
9
  s.homepage = %q{https://github.com/seoaqua/webpage}
10
10
  s.summary = s.description
11
- s.add_development_dependency 'mechanize'
11
+ s.add_development_dependency 'nokogiri'
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-29 00:00:00.000000000 Z
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: mechanize
15
+ name: nokogiri
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  version: '0'
61
61
  requirements: []
62
62
  rubyforge_project:
63
- rubygems_version: 1.8.24
63
+ rubygems_version: 1.8.25
64
64
  signing_key:
65
65
  specification_version: 3
66
66
  summary: a tool to extract some basic data from a webpage