synopsis 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -19,10 +19,8 @@ Jeweler::Tasks.new do |gem|
19
19
  gem.description = %Q{Web page synopsis from meta tags with fallback to bing screen scrape.}
20
20
  gem.email = "kenr@aeseducation.com"
21
21
  gem.authors = ["Ken Richard"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
22
  gem.add_runtime_dependency 'nokogiri', '> 1.4'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
23
+ gem.add_development_dependency 'rspec', '> 1.2.3'
26
24
  end
27
25
  Jeweler::RubygemsDotOrgTasks.new
28
26
 
@@ -44,8 +42,7 @@ task :default => :test
44
42
 
45
43
  require 'rake/rdoctask'
46
44
  Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : "0.0.1"
48
-
45
+ version = File.read('VERSION')
49
46
  rdoc.rdoc_dir = 'rdoc'
50
47
  rdoc.title = "synopsis #{version}"
51
48
  rdoc.rdoc_files.include('README*')
data/VERSION CHANGED
@@ -1,2 +1 @@
1
- 0.0.1
2
-
1
+ 0.0.3
@@ -1,8 +1,46 @@
1
1
  require 'nokogiri'
2
2
  require 'open-uri'
3
3
 
4
- dir = Pathname(__FILE__).dirname.expand_path
4
+ module Synopsis
5
5
 
6
- require dir + 'synopsis/meta'
7
- require dir + 'synopsis/bing_scrape'
8
- require dir + 'synopsis/main'
6
+ def self.synopsis(url)
7
+
8
+ doc = nil
9
+ description = nil
10
+
11
+ begin
12
+ doc = Nokogiri::HTML(open(url))
13
+ rescue
14
+ doc = nil
15
+ end
16
+
17
+ # Try the meta description tag first
18
+ if doc
19
+ doc.css('meta').each do |meta|
20
+ if meta.attributes['name'] && meta.attributes['name'].value == 'description'
21
+ description = meta.attributes['content'].value
22
+ end
23
+ end
24
+ end
25
+
26
+ # if that fails use bing
27
+ if description.nil? || description.length == 0
28
+ begin
29
+ bing_url = "http://www.bing.com/search?q=" + GI.escapeHTML(url)
30
+ bing_doc = Nokogiri::HTML(open(bing_url))
31
+ description = bing_doc.css('p').first.to_s.gsub(/<\/?[^>]*>/, "")
32
+ rescue
33
+ description = nil
34
+ end
35
+ end
36
+
37
+ # still failing grab the first para from the original doc
38
+ if description.nil? || description.length == 0
39
+ description = doc.css('p').first.to_s.gsub(/<\/?[^>]*>/, "")
40
+ end
41
+
42
+ description
43
+
44
+ end
45
+
46
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{synopsis}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ken Richard"]
@@ -25,9 +25,6 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/synopsis.rb",
28
- "lib/synopsis/bing_scrape.rb",
29
- "lib/synopsis/main.rb",
30
- "lib/synopsis/meta.rb",
31
28
  "synopsis.gemspec",
32
29
  "test/helper.rb",
33
30
  "test/test_synopsis.rb"
@@ -52,6 +49,7 @@ Gem::Specification.new do |s|
52
49
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
53
50
  s.add_development_dependency(%q<rcov>, [">= 0"])
54
51
  s.add_runtime_dependency(%q<nokogiri>, ["> 1.4"])
52
+ s.add_development_dependency(%q<rspec>, ["> 1.2.3"])
55
53
  else
56
54
  s.add_dependency(%q<nokogiri>, [">= 0"])
57
55
  s.add_dependency(%q<shoulda>, [">= 0"])
@@ -59,6 +57,7 @@ Gem::Specification.new do |s|
59
57
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
60
58
  s.add_dependency(%q<rcov>, [">= 0"])
61
59
  s.add_dependency(%q<nokogiri>, ["> 1.4"])
60
+ s.add_dependency(%q<rspec>, ["> 1.2.3"])
62
61
  end
63
62
  else
64
63
  s.add_dependency(%q<nokogiri>, [">= 0"])
@@ -67,6 +66,7 @@ Gem::Specification.new do |s|
67
66
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
68
67
  s.add_dependency(%q<rcov>, [">= 0"])
69
68
  s.add_dependency(%q<nokogiri>, ["> 1.4"])
69
+ s.add_dependency(%q<rspec>, ["> 1.2.3"])
70
70
  end
71
71
  end
72
72
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synopsis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ken Richard
@@ -107,6 +107,22 @@ dependencies:
107
107
  version: "1.4"
108
108
  name: nokogiri
109
109
  version_requirements: *id006
110
+ - !ruby/object:Gem::Dependency
111
+ prerelease: false
112
+ type: :development
113
+ requirement: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">"
117
+ - !ruby/object:Gem::Version
118
+ hash: 25
119
+ segments:
120
+ - 1
121
+ - 2
122
+ - 3
123
+ version: 1.2.3
124
+ name: rspec
125
+ version_requirements: *id007
110
126
  description: Web page synopsis from meta tags with fallback to bing screen scrape.
111
127
  email: kenr@aeseducation.com
112
128
  executables: []
@@ -125,9 +141,6 @@ files:
125
141
  - Rakefile
126
142
  - VERSION
127
143
  - lib/synopsis.rb
128
- - lib/synopsis/bing_scrape.rb
129
- - lib/synopsis/main.rb
130
- - lib/synopsis/meta.rb
131
144
  - synopsis.gemspec
132
145
  - test/helper.rb
133
146
  - test/test_synopsis.rb
@@ -1,21 +0,0 @@
1
- module Synopsis
2
- class BingScrape
3
-
4
-
5
- def self.get(url)
6
- bing_url = "http://www.bing.com/search?q=" + url_escape(url)
7
- doc = Nokogiri::HTML(open(url))
8
- description = nil
9
- description = doc.css('p').first.to_s
10
- end
11
-
12
-
13
- def self.url_escape(string)
14
- string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
15
- '%' + $1.unpack('H2' * $1.size).join('%').upcase
16
- end.tr(' ', '+')
17
- end
18
-
19
-
20
- end
21
- end
@@ -1,7 +0,0 @@
1
- module Synopsis
2
-
3
- def self.synopsis(url)
4
- description = Meta.get(url) or BingScrape.get(url)
5
- end
6
-
7
- end
@@ -1,16 +0,0 @@
1
- module Synopsis
2
- class Meta
3
-
4
- def self.get(url)
5
- doc = Nokogiri::HTML(open(url))
6
- description = nil
7
- doc.css('meta').each do |meta|
8
- if meta.attributes['name'] && meta.attributes['name'].value == 'description'
9
- description = meta.attributes['content'].value
10
- end
11
- end
12
- description
13
- end
14
-
15
- end
16
- end