comparateur 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +14 -0
- data/README.md +9 -2
- data/Rakefile +4 -0
- data/bin/comparateur +29 -0
- data/comparateur.gemspec +2 -0
- data/lib/comparateur/version.rb +1 -1
- data/spec/comparateur_spec.rb +90 -0
- data/spec/spec_helper.rb +15 -0
- metadata +40 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74bfc3df2e2ed6df39c92bce5fdd293fa6a002fa
|
4
|
+
data.tar.gz: 7c2ecfaacee39d2e86d6dde7d7ecae9b11c6f8b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebc98d46932ccb8789c4e18b5d1ae18fb6e2cfa4bb163e05cd26a2fc308f4c6d1dd2b92e92cf1702ab3f92c5a2597b44288678e57fe54c78a39218272410d442
|
7
|
+
data.tar.gz: 2b781f602c35dd84be3cc313c1ab5156ab005b5313bc16f2ae0fc04a94f6f81dc5e8a9cd2aed30879ef93147edd42b11a4ce98eb7b64ef08f6111edac6e1758a
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Comparateur
|
2
2
|
|
3
|
-
[](https://travis-ci.org/radubogdan/ruby-comparateur) [](http://badge.fury.io/rb/comparateur)
|
4
4
|
|
5
5
|
Calculate the structural similarity between two HTML documents.
|
6
6
|
|
@@ -29,6 +29,8 @@ Or install it yourself as:
|
|
29
29
|
|
30
30
|
## Usage
|
31
31
|
|
32
|
+
**From Ruby**
|
33
|
+
|
32
34
|
```ruby
|
33
35
|
require 'comparateur'
|
34
36
|
|
@@ -42,7 +44,12 @@ duckduck_url = "https://duckduckgo.com"
|
|
42
44
|
LeComparateur.compare_urls(google_url, duckduck_url) # 0.3815789473684211
|
43
45
|
```
|
44
46
|
|
45
|
-
|
47
|
+
Long Ruby example [here](https://raw.githubusercontent.com/radubogdan/ruby-comparateur/master/examples/a.rb)
|
48
|
+
|
49
|
+
**From terminal**
|
50
|
+
```
|
51
|
+
$ comparateur http://google.com https://duckduckgo.com
|
52
|
+
```
|
46
53
|
|
47
54
|
## Methods
|
48
55
|
|
data/Rakefile
CHANGED
data/bin/comparateur
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'comparateur'
|
4
|
+
|
5
|
+
class LeComparateur
|
6
|
+
extend Comparateur
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def url? url1, url2
|
10
|
+
reg = /^https?:\/\//
|
11
|
+
url1.match(reg) && url2.match(reg)
|
12
|
+
end
|
13
|
+
|
14
|
+
def help
|
15
|
+
puts "Please pass a valid URL\nExample: $ comparateur URL1 URL2"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
url1 = ARGV.shift
|
21
|
+
url2 = ARGV.shift
|
22
|
+
|
23
|
+
begin
|
24
|
+
if LeComparateur.url?(url1, url2)
|
25
|
+
puts LeComparateur.compare_urls(url1, url2)
|
26
|
+
else
|
27
|
+
LeComparateur.help
|
28
|
+
end
|
29
|
+
end
|
data/comparateur.gemspec
CHANGED
data/lib/comparateur/version.rb
CHANGED
@@ -0,0 +1,90 @@
|
|
1
|
+
require_relative '../lib/comparateur.rb'
|
2
|
+
|
3
|
+
describe Comparateur do
|
4
|
+
let(:extended_class) { Class.new { extend Comparateur } }
|
5
|
+
let(:included_class) { Class.new { include Comparateur } }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@str1 = "<html><body><ul><li><ul><li></li></ul></li></ul></body></html"
|
9
|
+
@str2 = "<html><body><ul><li></li></ul></body></html"
|
10
|
+
@nok1 = Nokogiri::HTML(@str1)
|
11
|
+
@nok2 = Nokogiri::HTML(@str2)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "serialize_nokogiri_html" do
|
15
|
+
it "should return array" do
|
16
|
+
expect(extended_class.serialize_nokogiri_html(@nok1).class).to eq Array
|
17
|
+
expect(included_class.new.serialize_nokogiri_html(@nok1).class).to eq Array
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return array with value" do
|
21
|
+
expect(extended_class.serialize_nokogiri_html(@nok1)).to eq %w(html body ul li ul li)
|
22
|
+
expect(included_class.new.serialize_nokogiri_html(@nok1)).to eq %w(html body ul li ul li)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "serialize_url" do
|
27
|
+
it "should return array" do
|
28
|
+
expect(extended_class.serialize_url("http://google.com").class).to eq Array
|
29
|
+
expect(included_class.new.serialize_url("http://google.com").class).to eq Array
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "serialize_content" do
|
34
|
+
it "should return array" do
|
35
|
+
expect(extended_class.serialize_content(@str1).class).to eq Array
|
36
|
+
expect(included_class.new.serialize_content(@str1).class).to eq Array
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return array with value" do
|
40
|
+
expect(extended_class.serialize_content(@str1)).to eq %w(html body ul li ul li)
|
41
|
+
expect(included_class.new.serialize_content(@str1)).to eq %w(html body ul li ul li)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "compare_nokogiri_html" do
|
46
|
+
it "should return a Float number" do
|
47
|
+
expect(extended_class.compare_nokogiri_html(@nok1, @nok2).class).to eq Float
|
48
|
+
expect(included_class.new.compare_nokogiri_html(@nok1, @nok2).class).to eq Float
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return score" do
|
52
|
+
expect(extended_class.compare_nokogiri_html(@nok1, @nok2)).to eq 0.8
|
53
|
+
expect(included_class.new.compare_nokogiri_html(@nok1, @nok2)).to eq 0.8
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "compare_urls" do
|
58
|
+
it "should return a Float number" do
|
59
|
+
expect(extended_class.compare_urls("http://google.com", "https://duckduckgo.com").class).to eq Float
|
60
|
+
expect(included_class.new.compare_urls("http://google.com", "https://duckduckgo.com").class).to eq Float
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "compare_content" do
|
65
|
+
it "should return a Float number" do
|
66
|
+
expect(extended_class.compare_content(@str1, @str2).class).to eq Float
|
67
|
+
expect(included_class.new.compare_content(@str1, @str2).class).to eq Float
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return score" do
|
71
|
+
expect(extended_class.compare_content(@str1, @str2)).to eq 0.8
|
72
|
+
expect(included_class.new.compare_content(@str1, @str2)).to eq 0.8
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "lcs" do
|
77
|
+
arr1 = %w(html body h1 a)
|
78
|
+
arr2 = %w(html body h1 ul)
|
79
|
+
|
80
|
+
it "should return score" do
|
81
|
+
expect(extended_class.lcs(arr1, arr2)).to eq 0.75
|
82
|
+
expect(included_class.new.lcs(arr1, arr2)).to eq 0.75
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should return a Float number" do
|
86
|
+
expect(extended_class.lcs(arr1, arr2).class).to eq Float
|
87
|
+
expect(included_class.new.lcs(arr1, arr2).class).to eq Float
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.expect_with :rspec do |expectations|
|
3
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
4
|
+
end
|
5
|
+
|
6
|
+
config.mock_with :rspec do |mocks|
|
7
|
+
mocks.verify_partial_doubles = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.warnings = true
|
11
|
+
|
12
|
+
config.profile_examples = 10
|
13
|
+
|
14
|
+
config.order = :random
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comparateur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radu-Bogdan Croitoru
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -66,22 +66,56 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description:
|
70
98
|
email:
|
71
99
|
- croitoruradubogdan@gmail.com
|
72
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- comparateur
|
73
102
|
extensions: []
|
74
103
|
extra_rdoc_files: []
|
75
104
|
files:
|
76
105
|
- .gitignore
|
106
|
+
- .rspec
|
107
|
+
- .travis.yml
|
77
108
|
- Gemfile
|
78
109
|
- LICENSE.txt
|
79
110
|
- README.md
|
80
111
|
- Rakefile
|
112
|
+
- bin/comparateur
|
81
113
|
- comparateur.gemspec
|
82
114
|
- examples/a.rb
|
83
115
|
- lib/comparateur.rb
|
84
116
|
- lib/comparateur/version.rb
|
117
|
+
- spec/comparateur_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
85
119
|
homepage: https://github.com/radubogdan/ruby-comparateur
|
86
120
|
licenses:
|
87
121
|
- MIT
|
@@ -106,4 +140,6 @@ rubygems_version: 2.0.14
|
|
106
140
|
signing_key:
|
107
141
|
specification_version: 4
|
108
142
|
summary: Calculate the structural similarity between two HTML documents
|
109
|
-
test_files:
|
143
|
+
test_files:
|
144
|
+
- spec/comparateur_spec.rb
|
145
|
+
- spec/spec_helper.rb
|