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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3396baff4b80834299a15ffabeb73748ef16c6f5
4
- data.tar.gz: 9d1fca09a2658a2c3ac0de11f29846040744d912
3
+ metadata.gz: 74bfc3df2e2ed6df39c92bce5fdd293fa6a002fa
4
+ data.tar.gz: 7c2ecfaacee39d2e86d6dde7d7ecae9b11c6f8b5
5
5
  SHA512:
6
- metadata.gz: 13e9616ca619fd82cdbfe5f1625663a0da7fd9a72bf1a1cbf9f70ff18e481773b6963e3cdafa5c3399decca0aa4bacfae47f0decdc2af652ab45dbc77b3163df
7
- data.tar.gz: df66d064b6d2446d47225c381c64a37e395196fedba86e0b6af0e4941074e5acca107369ba7a5e1a497c13b7594f65546c75153f8f7c894dc932ed04c5ef663c
6
+ metadata.gz: ebc98d46932ccb8789c4e18b5d1ae18fb6e2cfa4bb163e05cd26a2fc308f4c6d1dd2b92e92cf1702ab3f92c5a2597b44288678e57fe54c78a39218272410d442
7
+ data.tar.gz: 2b781f602c35dd84be3cc313c1ab5156ab005b5313bc16f2ae0fc04a94f6f81dc5e8a9cd2aed30879ef93147edd42b11a4ce98eb7b64ef08f6111edac6e1758a
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - 2.0.0
6
+
7
+ script: 'bundle exec rspec spec/'
8
+
9
+ notifications:
10
+ email:
11
+ recipients:
12
+ - croitoruradubogdan@gmail.com
13
+ on_failure: change
14
+ on_success: never
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Comparateur
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/comparateur.svg)](http://badge.fury.io/rb/comparateur) [![comparateur Downloads](http://www.gemetric.me/images/comparateur.gif)](https://rubygems.org/gems/comparateur)
3
+ [![Build Status](https://travis-ci.org/radubogdan/ruby-comparateur.svg?branch=master)](https://travis-ci.org/radubogdan/ruby-comparateur) [![Gem Version](https://badge.fury.io/rb/comparateur.svg)](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
- Example of usage [here](https://raw.githubusercontent.com/radubogdan/ruby-comparateur/master/examples/a.rb)
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
@@ -1,2 +1,6 @@
1
+ require "rspec/core/rake_task"
1
2
  require "bundler/gem_tasks"
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
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
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.6"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "pry"
25
27
  end
@@ -1,3 +1,3 @@
1
1
  module Comparateur
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -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
@@ -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.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-06 00:00:00.000000000 Z
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