plagiarism2 0.0.6 → 0.0.7

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: a5ae907124afcc6b114cb2fd1a575b7d0a4c5c85
4
- data.tar.gz: b6c4a942896b1933ce60a7e3216b8c839bf422a5
3
+ metadata.gz: 8f4e43615c24c041d05466d83091b775a26bcde1
4
+ data.tar.gz: 2fc69b5c28c9a5da3726765071fc21323bc80ac3
5
5
  SHA512:
6
- metadata.gz: bb93fde868664ee036d0fdaa13ee7de53235a372ec41daf5d72109f490b6985094e44afbd8cd189b77693f1a9283d2216010b7c040a5792505874b58e321ffdd
7
- data.tar.gz: 93f3cf1b8fed1d7071a80ce4c92383beec0a1b49de3d27f6956c645cc269b8140e4b16d86bfd63384def1ab4ffa8feb9a70b8bf24dfe610f61f120e7b7ea65ef
6
+ metadata.gz: 5f97108d3ff54b682628ae1328f67726871761cd2121aace55debb7784cdbd5fe21b6d4c7e1661562ed30853bf0afba3397540d3c3e8d62bdd89f2f5dd315841
7
+ data.tar.gz: e4e2014486db66aecb23159296c1e03578542e2b1ce3b13a8bbbcf883967640335588e476882d2f1fcf4a67fcbd2649eb73e31b94d7233c90039633cde942904
data/README.md CHANGED
@@ -44,20 +44,27 @@ config.google_key = xxx
44
44
  config.google_cx = xx
45
45
  ```
46
46
 
47
- After that you can check the unique of content
47
+ ###### Plagiarism.unique?
48
48
 
49
49
  ```ruby
50
50
  text = 'Latte user story paradigm affordances experiential innovate venture capital physical computing. Ship it agile actionable insight iterate thought leader pitch deck experiential iterate. Venture capital food-truck quantitative vs. qualitative SpaceTeam convergence agile.'
51
- Plagiarism.unique? text
51
+ Plagiarism.unique? text # => true
52
52
  ```
53
53
 
54
54
  `Plagiarism.unique?` is true when all strategies is true
55
55
 
56
+ ###### Plagiarism.match
57
+
58
+ ```ruby
59
+ Plagiarism.match 'ringmd' # => 'www.ring.md'
60
+ ```
61
+
56
62
  #### Bash
57
63
 
58
64
  ```bash
59
- plagiarism init # generate config
60
- plagiarism unique -c="ringmd" # check unique
65
+ plagiarism init # generate config, default ~/.plagiarism.yml
66
+ plagiarism unique -c="ringmd" # => false
67
+ plagiarism match -c="ringmd" # => 'www.ring.md'
61
68
  ```
62
69
 
63
70
  For more details, you can use help
@@ -9,9 +9,9 @@ module Plagiarism
9
9
  Typhoeus.get(URL, params: params.merge('$format' => :json, 'Query' => "'#{content}'"), userpwd: ":#{Config.bing_key}")
10
10
  end
11
11
 
12
- def iterate(response)
12
+ def iterate(response, action = :all?)
13
13
  results = JSON.parse(response)['d']['results'] rescue []
14
- results.all? do |r|
14
+ results.send(action) do |r|
15
15
  uri = URI.parse URI::encode(r['Url'])
16
16
  yield uri
17
17
  end
@@ -9,10 +9,10 @@ module Plagiarism
9
9
  Typhoeus.get(URL, params: params.merge(q: content))
10
10
  end
11
11
 
12
- def iterate(response)
12
+ def iterate(response, action = :all?)
13
13
  doc = Nokogiri::HTML response
14
- doc.css('.results_links_deep:not(.result--no-result)').all? do |row|
15
- href = row.at_css('.result__a').attributes['href'].value rescue ''
14
+ doc.css('.results_links_deep:not(.result--no-result) .result__a').send(action) do |row|
15
+ href = row.attributes['href'].value rescue ''
16
16
  uri = URI.parse URI::encode(href)
17
17
  yield uri
18
18
  end
@@ -10,7 +10,7 @@ module Plagiarism
10
10
  raise
11
11
  end
12
12
 
13
- def iterate(r)
13
+ def iterate(r, a = :all?)
14
14
  raise
15
15
  end
16
16
 
@@ -51,7 +51,7 @@ module Plagiarism
51
51
  end
52
52
 
53
53
  def retrieve_link(response)
54
- self.class.iterate(response) { |uri| uri.host !~ self.class.whitelists_regex and return uri.to_s }
54
+ self.class.iterate(response, :find) { |uri| uri.host !~ self.class.whitelists_regex and return uri.to_s }
55
55
  end
56
56
 
57
57
  end
@@ -10,9 +10,9 @@ module Plagiarism
10
10
  Typhoeus.get URL, params: params.merge(v: VERSION, q: content, rsz: :large)
11
11
  end
12
12
 
13
- def iterate(response)
13
+ def iterate(response, action = :all?)
14
14
  results = JSON.parse(response)['responseData']['results'] rescue []
15
- results.all? do |r|
15
+ results.send(action) do |r|
16
16
  uri = URI.parse URI::encode(r['unescapedUrl'])
17
17
  yield uri
18
18
  end
@@ -16,9 +16,9 @@ module Plagiarism
16
16
  )
17
17
  end
18
18
 
19
- def iterate(response)
19
+ def iterate(response, action = :all?)
20
20
  results = JSON.parse(response)['items'] || []
21
- results.all? do |r|
21
+ results.send(action) do |r|
22
22
  uri = URI.parse URI::encode(r['link'])
23
23
  yield uri
24
24
  end
@@ -6,13 +6,13 @@ module Plagiarism
6
6
  class << self
7
7
 
8
8
  def fetch(content, params)
9
- Typhoeus.get(URL, params: params.merge(p: content))
9
+ Typhoeus.get(URL, params: params.merge(p: content), headers: { 'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' })
10
10
  end
11
11
 
12
- def iterate(response)
12
+ def iterate(response, action = :all?)
13
13
  doc = Nokogiri::HTML response
14
- doc.css('.searchCenterMiddle li').all? do |row|
15
- href = row.at_css('.compTitle a').attributes['href'].value rescue ''
14
+ doc.css('.searchCenterMiddle li .compTitle a').send(action) do |row|
15
+ href = row.attributes['href'].value
16
16
  uri = URI.parse URI::encode(href)
17
17
  yield uri
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module Plagiarism
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plagiarism2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - MQuy