webpage 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/webpage.rb +2 -5
- data/spec/webpage_spec.rb +3 -0
- data/webpage.gemspec +1 -1
- metadata +1 -1
data/lib/webpage.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
#coding:UTF-8
|
2
2
|
require 'webpage/common'
|
3
3
|
class Webpage
|
4
|
+
attr_reader :nokogiri
|
4
5
|
def initialize(body,options={})
|
5
6
|
raise ArgumentError 'body cannot be empty' unless body
|
6
|
-
@body = body
|
7
7
|
@options = options
|
8
8
|
#@body = @body.force_encoding(@options[:encoding]).encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "") if @options.has_key?:encoding
|
9
|
-
@nokogiri = Nokogiri::HTML(
|
9
|
+
@nokogiri = Nokogiri::HTML(body)
|
10
10
|
if options.has_key?:uri
|
11
11
|
@uri = fuzzy_uri(@options[:uri])
|
12
12
|
raise '@uri should be absolute' unless @uri.absolute?
|
@@ -37,9 +37,6 @@ class Webpage
|
|
37
37
|
def nodes_with(key)
|
38
38
|
@nokogiri.xpath("//@#{key}")
|
39
39
|
end
|
40
|
-
def xpath(xstring)
|
41
|
-
@nokogiri.xpath(xstring)
|
42
|
-
end
|
43
40
|
|
44
41
|
def keywords
|
45
42
|
@keywords ||= @nokogiri.xpath("//meta[@name='keywords']").map{|meta|meta['content']}.flatten.join.split(',')
|
data/spec/webpage_spec.rb
CHANGED
@@ -28,6 +28,9 @@ describe Webpage do
|
|
28
28
|
it "links should be an array" do
|
29
29
|
page.links.class.should == Array
|
30
30
|
end
|
31
|
+
it "['h1'].to_a should return Array" do
|
32
|
+
page['h1'].to_a.class.should == Array
|
33
|
+
end
|
31
34
|
|
32
35
|
it "[] should return class Nokogiri::XML::NodeSet" do
|
33
36
|
%w(canonical keywords description).each do |tag|
|
data/webpage.gemspec
CHANGED