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 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(@body)
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{webpage}
3
- s.version = '0.0.8'
3
+ s.version = '0.0.9'
4
4
  s.authors = ["seoaqua"]
5
5
  s.date = %q{2012-07-29}
6
6
  s.description = %q{a tool to extract some basic data from a webpage}
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.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: