metainspector 1.17.0 → 1.17.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54f34fbd4dec77ffa68eb9762cdc140e98246817
4
- data.tar.gz: 0c294be322b646fa90150c3934218db529af3c6b
3
+ metadata.gz: ca50a3bad8a3a8f98f2dcdd6c5e5223ef78b8066
4
+ data.tar.gz: 5e3b651a1fd60fa5a63929a22880f87c28fe515b
5
5
  SHA512:
6
- metadata.gz: 79a235d8161922f9991f9df68a524f18076562c56ff68cee29a4ac8dc88c6abd1b1113363aaa9d79b39e9f703abcdcc801ccd24930c3a085157979814498c132
7
- data.tar.gz: 68b165770c8c8de5d56b923c9b25405f500ac3ee00bfb245af41a91dcf9d2ac7fcb1bf6fcbf6d6ec80b9f7453462d2c2235a14109a0a09710ec424d5f4b59a08
6
+ metadata.gz: 804bba1881a89677070abb29f98b0a516a80390d85a451e47178840093b3f8c98696f41edffe54811a1ffa26dc44d7e1e3448410612750385f2d20f35b1faf61
7
+ data.tar.gz: 60b8073a5062ea856dcfa38e23913a69dd654f2e4f23ae651912b07b61bc4c27a451bee586e6de29472ef5a786f61d08f33563479c71a185318ed10be1fb93db
@@ -39,7 +39,7 @@ module MetaInspector
39
39
  extend Forwardable
40
40
  def_delegators :@url, :url, :scheme, :host, :root_url
41
41
  def_delegators :@request, :content_type
42
- def_delegators :@parser, :parsed, :method_missing, :title, :description, :links, :internal_links, :external_links,
42
+ def_delegators :@parser, :parsed, :method_missing, :respond_to?, :title, :description, :links, :internal_links, :external_links,
43
43
  :images, :image, :feed, :charset
44
44
 
45
45
  # Returns all document data as a nested Hash
@@ -0,0 +1,18 @@
1
+ module MetaInspector
2
+
3
+ # Encapsulates matching for method_missing and respond_to? for meta tags methods
4
+ class MetaTagsDynamicMatch
5
+ attr_reader :meta_tag
6
+
7
+ def initialize(method_name)
8
+ if method_name.to_s =~ /^meta_(.+)/
9
+ @meta_tag = $1
10
+ end
11
+ end
12
+
13
+ def match?
14
+ @meta_tag
15
+ end
16
+
17
+ end
18
+ end
@@ -83,6 +83,10 @@ module MetaInspector
83
83
  @charset ||= (charset_from_meta_charset || charset_from_meta_content_type)
84
84
  end
85
85
 
86
+ def respond_to?(method_name, include_private = false)
87
+ MetaInspector::MetaTagsDynamicMatch.new(method_name).match? || super
88
+ end
89
+
86
90
  private
87
91
 
88
92
  def defaults
@@ -95,10 +99,11 @@ module MetaInspector
95
99
  #
96
100
  # It will first try with meta name="..." and if nothing found,
97
101
  # with meta http-equiv="...", substituting "_" by "-"
98
- # TODO: define respond_to? to return true on the meta_name methods
99
102
  def method_missing(method_name)
100
- if method_name.to_s =~ /^meta_(.*)/
101
- key = $1
103
+ meta_tags_method = MetaInspector::MetaTagsDynamicMatch.new(method_name)
104
+
105
+ if meta_tags_method.match?
106
+ key = meta_tags_method.meta_tag
102
107
 
103
108
  #special treatment for opengraph (og:) and twitter card (twitter:) tags
104
109
  key.gsub!("_",":") if key =~ /^og_(.*)/ || key =~ /^twitter_(.*)/
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module MetaInspector
4
- VERSION = "1.17.0"
4
+ VERSION = "1.17.1"
5
5
  end
@@ -5,6 +5,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'meta_inspector/excep
5
5
  require File.expand_path(File.join(File.dirname(__FILE__), 'meta_inspector/exception_log'))
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), 'meta_inspector/request'))
7
7
  require File.expand_path(File.join(File.dirname(__FILE__), 'meta_inspector/url'))
8
+ require File.expand_path(File.join(File.dirname(__FILE__), 'meta_inspector/meta_tags_dynamic_match'))
8
9
  require File.expand_path(File.join(File.dirname(__FILE__), 'meta_inspector/parser'))
9
10
  require File.expand_path(File.join(File.dirname(__FILE__), 'meta_inspector/document'))
10
11
  require File.expand_path(File.join(File.dirname(__FILE__), 'meta_inspector/deprecations'))
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.description = %q{MetaInspector lets you scrape a web page and get its title, charset, link and meta tags}
8
8
  gem.summary = %q{MetaInspector is a ruby gem for web scraping purposes, that returns a hash with metadata from a given URL}
9
9
  gem.homepage = "http://jaimeiniesta.github.io/metainspector/"
10
+ gem.license = "MIT"
10
11
 
11
12
  gem.files = `git ls-files`.split("\n")
12
13
  gem.test_files = `git ls-files -- {spec}/*`.split("\n")
data/spec/parser_spec.rb CHANGED
@@ -267,6 +267,46 @@ describe MetaInspector::Parser do
267
267
  end
268
268
  end
269
269
 
270
+ describe 'respond_to? for meta tags ghost methods' do
271
+ before(:each) do
272
+ @m = MetaInspector.new('http://pagerankalert.com')
273
+ end
274
+
275
+ it "should return true for meta tags as string" do
276
+ @m.respond_to?("meta_robots").should be_true
277
+ end
278
+
279
+ it "should return true for meta tags as symbols" do
280
+ @m.respond_to?(:meta_robots).should be_true
281
+ end
282
+
283
+ it "should return true for meta_twitter_site as string" do
284
+ @m = MetaInspector.new('http://www.youtube.com/watch?v=iaGSSrp49uc')
285
+ @m.respond_to?("meta_twitter_site").should be_true
286
+ end
287
+
288
+ it "should return true for meta_twitter_site as symbol" do
289
+ @m = MetaInspector.new('http://www.youtube.com/watch?v=iaGSSrp49uc')
290
+ @m.respond_to?(:meta_twitter_player_width).should be_true
291
+ end
292
+ end
293
+
294
+ describe 'respond_to? for not implemented methods' do
295
+
296
+ before(:each) do
297
+ @m = MetaInspector.new('http://pagerankalert.com')
298
+ end
299
+
300
+ it "should return false when method name passed as string" do
301
+ @m.respond_to?("method_not_implemented").should be_false
302
+ end
303
+
304
+ it "should return false when method name passed as symbols" do
305
+ @m = MetaInspector.new('http://www.youtube.com/watch?v=iaGSSrp49uc')
306
+ @m.respond_to?(:method_not_implemented).should be_false
307
+ end
308
+ end
309
+
270
310
  describe 'Getting meta tags by ghost methods' do
271
311
  before(:each) do
272
312
  @m = MetaInspector::Parser.new(doc 'http://pagerankalert.com')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metainspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.0
4
+ version: 1.17.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Iniesta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-22 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -142,6 +142,7 @@ files:
142
142
  - lib/meta_inspector/document.rb
143
143
  - lib/meta_inspector/exception_log.rb
144
144
  - lib/meta_inspector/exceptionable.rb
145
+ - lib/meta_inspector/meta_tags_dynamic_match.rb
145
146
  - lib/meta_inspector/parser.rb
146
147
  - lib/meta_inspector/request.rb
147
148
  - lib/meta_inspector/url.rb
@@ -186,7 +187,8 @@ files:
186
187
  - spec/spec_helper.rb
187
188
  - spec/url_spec.rb
188
189
  homepage: http://jaimeiniesta.github.io/metainspector/
189
- licenses: []
190
+ licenses:
191
+ - MIT
190
192
  metadata: {}
191
193
  post_install_message:
192
194
  rdoc_options: []
@@ -194,17 +196,17 @@ require_paths:
194
196
  - lib
195
197
  required_ruby_version: !ruby/object:Gem::Requirement
196
198
  requirements:
197
- - - ! '>='
199
+ - - '>='
198
200
  - !ruby/object:Gem::Version
199
201
  version: '0'
200
202
  required_rubygems_version: !ruby/object:Gem::Requirement
201
203
  requirements:
202
- - - ! '>='
204
+ - - '>='
203
205
  - !ruby/object:Gem::Version
204
206
  version: '0'
205
207
  requirements: []
206
208
  rubyforge_project:
207
- rubygems_version: 2.0.5
209
+ rubygems_version: 2.1.3
208
210
  signing_key:
209
211
  specification_version: 4
210
212
  summary: MetaInspector is a ruby gem for web scraping purposes, that returns a hash