ogp 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +120 -0
- data/.travis.yml +8 -0
- data/README.md +13 -2
- data/Rakefile +1 -1
- data/lib/ogp/open_graph.rb +24 -28
- data/lib/ogp/version.rb +1 -1
- data/ogp.gemspec +5 -3
- data/spec/ogp/open_graph_spec.rb +5 -5
- data/spec/spec_helper.rb +0 -4
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca2fa62d7e09874c7999112994aa53385734c2b1
|
4
|
+
data.tar.gz: e44b5cb9f6eebf69a0a1e03f931f9502af687f10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 824aee85a548ab9eb7cbcf46369567f238b01bac1a2d9969d82bad2b5b182a004e071c91a33bab8cb9045bc0a5052c91c5647362e666a7bf528f75e928fde6ae
|
7
|
+
data.tar.gz: 9b16c4795d015b03fe307dc98a0ce4830d8ae70c85de99a7072d2f5943f1f85ae1b0174926ce14a83d35c9bc910a9300224582f586dedaae1d929b4c28914bed
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
Include:
|
4
|
+
- Rakefile
|
5
|
+
- config.ru
|
6
|
+
- Gemfile
|
7
|
+
- app/tasks/**/*.rake
|
8
|
+
Exclude:
|
9
|
+
- bin/**
|
10
|
+
- db/schema.rb
|
11
|
+
- db/migrate/**
|
12
|
+
- script/**
|
13
|
+
- vendor/**/*
|
14
|
+
- node_modules/**/*
|
15
|
+
TargetRubyVersion: 2.3
|
16
|
+
|
17
|
+
Rails:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Documentation:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Encoding:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
LineLength:
|
27
|
+
Max: 200
|
28
|
+
|
29
|
+
AccessModifierIndentation:
|
30
|
+
EnforcedStyle: outdent
|
31
|
+
|
32
|
+
IfUnlessModifier:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
CaseIndentation:
|
36
|
+
EnforcedStyle: end
|
37
|
+
IndentOneStep: true
|
38
|
+
|
39
|
+
MethodLength:
|
40
|
+
CountComments: false
|
41
|
+
Max: 25
|
42
|
+
|
43
|
+
SignalException:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
ColonMethodCall:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
AsciiComments:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
RegexpLiteral:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
AssignmentInCondition:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
ParameterLists:
|
59
|
+
CountKeywordArgs: false
|
60
|
+
|
61
|
+
SingleLineBlockParams:
|
62
|
+
Methods:
|
63
|
+
- reduce:
|
64
|
+
- memo
|
65
|
+
- item
|
66
|
+
|
67
|
+
MethodCalledOnDoEndBlock:
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
Metrics/AbcSize:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Style/CollectionMethods:
|
74
|
+
Enabled: true
|
75
|
+
|
76
|
+
Style/SymbolArray:
|
77
|
+
Enabled: true
|
78
|
+
|
79
|
+
Layout/ExtraSpacing:
|
80
|
+
Enabled: true
|
81
|
+
|
82
|
+
Layout/MultilineMethodCallIndentation:
|
83
|
+
Enabled: false
|
84
|
+
|
85
|
+
Layout/IndentArray:
|
86
|
+
Enabled: false
|
87
|
+
|
88
|
+
Layout/AlignHash:
|
89
|
+
Enabled: false
|
90
|
+
|
91
|
+
Layout/AlignParameters:
|
92
|
+
EnforcedStyle: with_fixed_indentation
|
93
|
+
|
94
|
+
Style/FrozenStringLiteralComment:
|
95
|
+
Enabled: false
|
96
|
+
|
97
|
+
Rails/SkipsModelValidations:
|
98
|
+
Enabled: false
|
99
|
+
|
100
|
+
Metrics/BlockLength:
|
101
|
+
Max: 200
|
102
|
+
|
103
|
+
Style/PercentLiteralDelimiters:
|
104
|
+
PreferredDelimiters:
|
105
|
+
'%i': '()'
|
106
|
+
'%I': '()'
|
107
|
+
'%w': '()'
|
108
|
+
'%W': '()'
|
109
|
+
|
110
|
+
Layout/SpaceInLambdaLiteral:
|
111
|
+
Enabled: false
|
112
|
+
|
113
|
+
Bundler/OrderedGems:
|
114
|
+
Enabled: false
|
115
|
+
|
116
|
+
Rails/OutputSafety:
|
117
|
+
Enabled: false
|
118
|
+
|
119
|
+
Performance/StringReplacement:
|
120
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
-
|
1
|
+
<p align="center">
|
2
|
+
<a href="https://github.com/mirego/ogp">
|
3
|
+
<img src="https://i.imgur.com/qZrMsLq.png" alt="ogp" />
|
4
|
+
</a>
|
5
|
+
<br />
|
6
|
+
OGP is a minimalist Ruby library that does only one thing: parse Open Graph protocol information. For more information: <a href="http://ogp.me">http://ogp.me</a>.
|
7
|
+
<br /><br />
|
8
|
+
<a href="https://rubygems.org/gems/ogp"><img src="http://img.shields.io/gem/v/ogp.svg" /></a>
|
9
|
+
<a href="https://codeclimate.com/github/jcouture/ogp"><img src="http://img.shields.io/codeclimate/github/jcouture/ogp.svg" /></a>
|
10
|
+
<a href="https://gemnasium.com/jcouture/ogp"><img src="http://img.shields.io/gemnasium/jcouture/ogp.svg" /></a>
|
11
|
+
<a href="https://travis-ci.org/jcouture/ogp"><img src="http://img.shields.io/travis/jcouture/ogp.svg" /></a>
|
12
|
+
</p>
|
2
13
|
|
3
|
-
OGP is a minimalist Ruby library that does only one thing: parse Open Graph protocol information from web sites. For more information: http://ogp.me.
|
4
14
|
|
5
15
|
## Installation
|
6
16
|
|
@@ -44,3 +54,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jcoutu
|
|
44
54
|
|
45
55
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
46
56
|
|
57
|
+
The OGP pirate logo is based on [this icon](https://thenounproject.com/term/pirate/9414/) by [Simon Child](https://thenounproject.com/Simon%20Child/), from the Noun Project. Used under a [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/) license.
|
data/Rakefile
CHANGED
data/lib/ogp/open_graph.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'oga'
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
|
-
REQUIRED_ATTRIBUTES = %w(title type image url)
|
4
|
+
REQUIRED_ATTRIBUTES = %w(title type image url).freeze
|
5
5
|
|
6
6
|
module OGP
|
7
7
|
class OpenGraph
|
8
8
|
# Required Accessors
|
9
9
|
attr_accessor :title, :type, :url
|
10
10
|
attr_accessor :images
|
11
|
-
|
11
|
+
|
12
12
|
# Optional Accessors
|
13
13
|
attr_accessor :description, :determiner, :site_name
|
14
14
|
attr_accessor :audios
|
@@ -17,12 +17,10 @@ module OGP
|
|
17
17
|
|
18
18
|
def initialize(source)
|
19
19
|
if source.nil? || source.empty?
|
20
|
-
raise ArgumentError
|
20
|
+
raise ArgumentError, '`source` cannot be nil or empty.'
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
raise MalformedSourceError
|
25
|
-
end
|
23
|
+
raise MalformedSourceError unless source.include?('</html>')
|
26
24
|
|
27
25
|
self.images = []
|
28
26
|
self.audios = []
|
@@ -35,17 +33,15 @@ module OGP
|
|
35
33
|
end
|
36
34
|
|
37
35
|
def image
|
38
|
-
return if
|
39
|
-
|
36
|
+
return if images.nil?
|
37
|
+
images.first
|
40
38
|
end
|
41
39
|
|
42
|
-
|
40
|
+
private
|
43
41
|
|
44
42
|
def check_required_attributes(document)
|
45
43
|
REQUIRED_ATTRIBUTES.each do |attribute_name|
|
46
|
-
|
47
|
-
raise MissingAttributeError.new("Missing required attribute: #{attribute_name}")
|
48
|
-
end
|
44
|
+
raise MissingAttributeError, "Missing required attribute: #{attribute_name}" unless attribute_exists(document, attribute_name)
|
49
45
|
end
|
50
46
|
end
|
51
47
|
|
@@ -53,22 +49,22 @@ module OGP
|
|
53
49
|
document.xpath('//head/meta[starts-with(@property, \'og:\')]').each do |attribute|
|
54
50
|
attribute_name = attribute.get('property').downcase.gsub('og:', '')
|
55
51
|
case attribute_name
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
52
|
+
when /^image$/i
|
53
|
+
images << OpenStruct.new(url: attribute.get('content').to_s)
|
54
|
+
when /^image:(.+)/i
|
55
|
+
images.last[Regexp.last_match[1].gsub('-', '_')] = attribute.get('content').to_s
|
56
|
+
when /^audio$/i
|
57
|
+
audios << OpenStruct.new(url: attribute.get('content').to_s)
|
58
|
+
when /^audio:(.+)/i
|
59
|
+
audios.last[Regexp.last_match[1].gsub('-', '_')] = attribute.get('content').to_s
|
60
|
+
when /^locale/i
|
61
|
+
locales << attribute.get('content').to_s
|
62
|
+
when /^video$/i
|
63
|
+
videos << OpenStruct.new(url: attribute.get('content').to_s)
|
64
|
+
when /^video:(.+)/i
|
65
|
+
videos.last[Regexp.last_match[1].gsub('-', '_')] = attribute.get('content').to_s
|
66
|
+
else
|
67
|
+
instance_variable_set("@#{attribute_name}", attribute.get('content'))
|
72
68
|
end
|
73
69
|
end
|
74
70
|
end
|
data/lib/ogp/version.rb
CHANGED
data/ogp.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'ogp/version'
|
@@ -9,13 +10,13 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ['Jean-Philippe Couture']
|
10
11
|
spec.email = ['jcouture@gmail.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
13
|
+
spec.summary = 'Simple Ruby library for parsing Open Graph prototocol information.'
|
14
|
+
spec.description = 'Simple Ruby library for parsing Open Graph prototocol information. See http://ogp.me for more information.'
|
14
15
|
spec.homepage = 'https://github.com/jcouture/ogp'
|
15
16
|
spec.license = 'MIT'
|
16
17
|
|
17
18
|
spec.files = `git ls-files`.split("\n")
|
18
|
-
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
20
|
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
21
|
spec.require_paths = ['lib']
|
21
22
|
|
@@ -24,4 +25,5 @@ Gem::Specification.new do |spec|
|
|
24
25
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
25
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
27
|
spec.add_development_dependency 'rspec', '~> 3.6'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 0.49.1'
|
27
29
|
end
|
data/spec/ogp/open_graph_spec.rb
CHANGED
@@ -17,26 +17,26 @@ describe OGP::OpenGraph do
|
|
17
17
|
context 'with missing one of the required attributes' do
|
18
18
|
it 'should raise an error' do
|
19
19
|
content = File.read("#{File.dirname(__FILE__)}/../fixtures/missing_required_attributes.html")
|
20
|
-
|
21
|
-
expect{OGP::OpenGraph.new(content)}.to raise_error(OGP::MissingAttributeError)
|
20
|
+
|
21
|
+
expect { OGP::OpenGraph.new(content) }.to raise_error(OGP::MissingAttributeError)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'with nil source' do
|
26
26
|
it 'should raise an error' do
|
27
|
-
expect{OGP::OpenGraph.new(nil)}.to raise_error(ArgumentError)
|
27
|
+
expect { OGP::OpenGraph.new(nil) }.to raise_error(ArgumentError)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'with empty source' do
|
32
32
|
it 'should raise an error' do
|
33
|
-
expect{OGP::OpenGraph.new('')}.to raise_error(ArgumentError)
|
33
|
+
expect { OGP::OpenGraph.new('') }.to raise_error(ArgumentError)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'with malformed source' do
|
38
38
|
it 'should raise an error' do
|
39
|
-
expect{OGP::OpenGraph.new('Lorem ipsum dolor sit amet, consectetur adipiscing elit.')}.to raise_error(OGP::MalformedSourceError)
|
39
|
+
expect { OGP::OpenGraph.new('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') }.to raise_error(OGP::MalformedSourceError)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ogp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Philippe Couture
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oga
|
@@ -66,8 +66,22 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.6'
|
69
|
-
|
70
|
-
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.49.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.49.1
|
83
|
+
description: Simple Ruby library for parsing Open Graph prototocol information. See
|
84
|
+
http://ogp.me for more information.
|
71
85
|
email:
|
72
86
|
- jcouture@gmail.com
|
73
87
|
executables: []
|
@@ -76,6 +90,8 @@ extra_rdoc_files: []
|
|
76
90
|
files:
|
77
91
|
- ".gitignore"
|
78
92
|
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".travis.yml"
|
79
95
|
- CODE_OF_CONDUCT.md
|
80
96
|
- Gemfile
|
81
97
|
- LICENSE.txt
|
@@ -117,7 +133,7 @@ rubyforge_project:
|
|
117
133
|
rubygems_version: 2.5.1
|
118
134
|
signing_key:
|
119
135
|
specification_version: 4
|
120
|
-
summary:
|
136
|
+
summary: Simple Ruby library for parsing Open Graph prototocol information.
|
121
137
|
test_files:
|
122
138
|
- spec/fixtures/audio_structured_attributes.html
|
123
139
|
- spec/fixtures/image_structured_attributes.html
|