linkser 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,8 @@ require 'net/https'
3
3
 
4
4
  module Linkser
5
5
  class Object
6
- extend ActiveSupport::Memoizable
7
-
8
6
  attr_reader :url, :last_url, :head
7
+
9
8
  def initialize url, last_url, head, options={}
10
9
  @url = url
11
10
  @last_url = last_url
@@ -14,6 +13,10 @@ module Linkser
14
13
  end
15
14
 
16
15
  def body
16
+ @body ||= build_body
17
+ end
18
+
19
+ def build_body
17
20
  uri = URI.parse last_url
18
21
  if uri.scheme and (uri.scheme.eql? "http" or uri.scheme.eql? "https")
19
22
  http = Net::HTTP.new uri.host, uri.port
@@ -32,9 +35,6 @@ module Linkser
32
35
  return response.body
33
36
  end
34
37
  end
35
-
36
- memoize :body
37
-
38
38
  end
39
39
  end
40
40
 
@@ -7,18 +7,44 @@ module Linkser
7
7
  class HTML < Linkser::Object
8
8
 
9
9
  def title
10
+ @title ||= build_title
11
+ end
12
+
13
+ def description
14
+ @description ||= build_description
15
+ end
16
+
17
+ def images
18
+ @images ||= build_images
19
+ end
20
+
21
+ def nokogiri
22
+ @nokogiri ||= Nokogiri::HTML(body)
23
+ end
24
+
25
+ def ogp
26
+ @ogp ||= build_ogp
27
+ end
28
+
29
+ def resource
30
+ @resource ||= build_resource
31
+ end
32
+
33
+ protected
34
+
35
+ def build_title
10
36
  ogp && ogp.title ||
11
37
  (e = nokogiri.css('title')).first && e.text
12
38
  end
13
39
 
14
- def description
40
+ def build_description
15
41
  ogp && ogp.description ||
16
42
  (e = nokogiri.css('meta').find { |meta|
17
43
  meta.get_attribute("name").eql? "description"
18
44
  }) && e.get_attribute("content")
19
45
  end
20
46
 
21
- def images
47
+ def build_images
22
48
  max_images = @options[:max_images] || 5
23
49
  Array.new.tap do |images|
24
50
  if ogp and ogp.image
@@ -52,11 +78,7 @@ module Linkser
52
78
  end
53
79
  end
54
80
 
55
- def nokogiri
56
- Nokogiri::HTML(body)
57
- end
58
-
59
- def ogp
81
+ def build_ogp
60
82
  ogp = OpenGraph::Object.new
61
83
  nokogiri.css('meta').each do |m|
62
84
  if m.attribute('property') && m.attribute('property').to_s.match(/^og:(.+)$/i)
@@ -66,14 +88,10 @@ module Linkser
66
88
  ogp = false if ogp.keys.empty? || !ogp.valid?
67
89
  ogp
68
90
  end
69
-
70
- def resource
71
- return Linkser::Resource.new ogp if ogp
72
- return nil
73
- end
74
91
 
75
- memoize :nokogiri, :ogp,
76
- :title, :description, :images, :resource
92
+ def build_resource
93
+ Linkser::Resource.new ogp if ogp
94
+ end
77
95
 
78
96
  private
79
97
 
@@ -1,3 +1,3 @@
1
1
  module Linkser
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
data/lib/linkser.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'active_support'
2
1
  require 'linkser/version'
3
2
 
4
3
  module Linkser
data/linkser.gemspec CHANGED
@@ -21,11 +21,10 @@ Gem::Specification.new do |s|
21
21
  # Gem dependencies
22
22
  #
23
23
  s.add_runtime_dependency('rake')
24
- s.add_runtime_dependency('nokogiri', '~> 1.4.2')
24
+ s.add_runtime_dependency('nokogiri', '>= 1.4.0')
25
25
  s.add_runtime_dependency('rmagick', '~> 2.13.1')
26
26
  s.add_runtime_dependency('ruby-imagespec', "~> 0.2.0")
27
27
  s.add_runtime_dependency('opengraph', "~> 0.0.4")
28
- s.add_runtime_dependency('activesupport', "> 2.2.1")
29
28
 
30
29
  # Development Gem dependencies
31
30
  #
metadata CHANGED
@@ -1,158 +1,90 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: linkser
3
- version: !ruby/object:Gem::Version
4
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.11
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 10
10
- version: 0.0.10
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Eduardo Casanova
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-02 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &71571270 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: nokogiri
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *71571270
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &71570900 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ~>
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 1
45
- - 4
46
- - 2
47
- version: 1.4.2
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.4.0
48
33
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: rmagick
52
34
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *71570900
36
+ - !ruby/object:Gem::Dependency
37
+ name: rmagick
38
+ requirement: &71569960 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
40
+ requirements:
56
41
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 57
59
- segments:
60
- - 2
61
- - 13
62
- - 1
42
+ - !ruby/object:Gem::Version
63
43
  version: 2.13.1
64
44
  type: :runtime
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: ruby-imagespec
68
45
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *71569960
47
+ - !ruby/object:Gem::Dependency
48
+ name: ruby-imagespec
49
+ requirement: &71569240 !ruby/object:Gem::Requirement
70
50
  none: false
71
- requirements:
51
+ requirements:
72
52
  - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 23
75
- segments:
76
- - 0
77
- - 2
78
- - 0
53
+ - !ruby/object:Gem::Version
79
54
  version: 0.2.0
80
55
  type: :runtime
81
- version_requirements: *id004
82
- - !ruby/object:Gem::Dependency
83
- name: opengraph
84
56
  prerelease: false
85
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *71569240
58
+ - !ruby/object:Gem::Dependency
59
+ name: opengraph
60
+ requirement: &71568630 !ruby/object:Gem::Requirement
86
61
  none: false
87
- requirements:
62
+ requirements:
88
63
  - - ~>
89
- - !ruby/object:Gem::Version
90
- hash: 23
91
- segments:
92
- - 0
93
- - 0
94
- - 4
64
+ - !ruby/object:Gem::Version
95
65
  version: 0.0.4
96
66
  type: :runtime
97
- version_requirements: *id005
98
- - !ruby/object:Gem::Dependency
99
- name: activesupport
100
- prerelease: false
101
- requirement: &id006 !ruby/object:Gem::Requirement
102
- none: false
103
- requirements:
104
- - - ">"
105
- - !ruby/object:Gem::Version
106
- hash: 5
107
- segments:
108
- - 2
109
- - 2
110
- - 1
111
- version: 2.2.1
112
- type: :runtime
113
- version_requirements: *id006
114
- - !ruby/object:Gem::Dependency
115
- name: ruby-debug
116
67
  prerelease: false
117
- requirement: &id007 !ruby/object:Gem::Requirement
118
- none: false
119
- requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- hash: 49
123
- segments:
124
- - 0
125
- - 10
126
- - 3
127
- version: 0.10.3
128
- type: :development
129
- version_requirements: *id007
130
- - !ruby/object:Gem::Dependency
68
+ version_requirements: *71568630
69
+ - !ruby/object:Gem::Dependency
131
70
  name: rspec
132
- prerelease: false
133
- requirement: &id008 !ruby/object:Gem::Requirement
71
+ requirement: &71568160 !ruby/object:Gem::Requirement
134
72
  none: false
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- hash: 19
139
- segments:
140
- - 2
141
- - 7
142
- - 0
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
143
76
  version: 2.7.0
144
77
  type: :development
145
- version_requirements: *id008
146
- description: Linkser is a link parser for Ruby. It gets an URI, tries to dereference it and returns the relevant information about the resource.
147
- email:
78
+ prerelease: false
79
+ version_requirements: *71568160
80
+ description: Linkser is a link parser for Ruby. It gets an URI, tries to dereference
81
+ it and returns the relevant information about the resource.
82
+ email:
148
83
  - ecasanovac@gmail.com
149
84
  executables: []
150
-
151
85
  extensions: []
152
-
153
86
  extra_rdoc_files: []
154
-
155
- files:
87
+ files:
156
88
  - .gitignore
157
89
  - .rspec
158
90
  - .travis.yml
@@ -171,36 +103,27 @@ files:
171
103
  - spec/spec_helper.rb
172
104
  homepage: https://github.com/ging/linkser
173
105
  licenses: []
174
-
175
106
  post_install_message:
176
107
  rdoc_options: []
177
-
178
- require_paths:
108
+ require_paths:
179
109
  - lib
180
- required_ruby_version: !ruby/object:Gem::Requirement
110
+ required_ruby_version: !ruby/object:Gem::Requirement
181
111
  none: false
182
- requirements:
183
- - - ">="
184
- - !ruby/object:Gem::Version
185
- hash: 3
186
- segments:
187
- - 0
188
- version: "0"
189
- required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
117
  none: false
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- hash: 3
195
- segments:
196
- - 0
197
- version: "0"
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
198
122
  requirements: []
199
-
200
123
  rubyforge_project:
201
- rubygems_version: 1.8.10
124
+ rubygems_version: 1.8.12
202
125
  signing_key:
203
126
  specification_version: 3
204
127
  summary: A link parser for Ruby
205
128
  test_files: []
206
-
129
+ has_rdoc: