ids_please 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95672c43728eb68bbbf5fbf8917e049120e8c7c6
4
- data.tar.gz: aab2241d2583ec30a539d87f6d4b3403ab5f1266
3
+ metadata.gz: 26c46bd87c6161d008f9f271aa4e784e701be728
4
+ data.tar.gz: f8c670dc5783dd145189c2c8b1ef0fd7cb2825e1
5
5
  SHA512:
6
- metadata.gz: 1859ae23f350b2ca328afbc0b51e58b95b0b1ec4f351025abb2a6f6f8a5d48f92d65b6dea16ebd608e8d9cb316c8358246ac34bafa92b30c2ccf88843b6f7e2d
7
- data.tar.gz: 8b5f4496318b59e43504a1981e40ed7c107800e14994abf5ab66d571cd5407914a891c7292eca1aed240af678f93164bafaafda50126d13f71ef97685cf6d1b8
6
+ metadata.gz: 7f4a8d777e9d1c8c8270e9d48a596e0bee359a53b7f78b6cce90a138b8e71260d2ce20bfda2ab7a0b192eeca364be881c5cf947bb547303da92ffee16db36789
7
+ data.tar.gz: 57712f6e90931fc6489f81728e9d20dc667d58a5d2a0a624c291771f1447e2a28804dee8310c3db3bd98f352a0a68464379b0b05fb707e23ffd805d87c17cf62
@@ -1,26 +1,28 @@
1
1
  class IdsPlease
2
2
  class BaseParser
3
3
 
4
- def self.to_sym
5
- self.name.split('::').last.downcase.to_sym
6
- end
4
+ class << self
5
+ def to_sym
6
+ self.name.split('::').last.downcase.to_sym
7
+ end
7
8
 
8
- def self.parse(links)
9
- links.map do |l|
10
- id = parse_link(l)
11
- matched_id = id.match(valid_id_regex) if id
12
- matched_id[1] if matched_id
13
- end.compact
14
- end
9
+ def parse(links)
10
+ links.map do |l|
11
+ id = parse_link(l)
12
+ matched_id = id.match(valid_id_regex) if id
13
+ matched_id[1] if matched_id
14
+ end.compact
15
+ end
15
16
 
16
- private
17
+ private
17
18
 
18
- def self.parse_link(link)
19
- link.path.split('/')[1]
20
- end
19
+ def parse_link(link)
20
+ link.path.split('/')[1]
21
+ end
21
22
 
22
- def self.valid_id_regex
23
- /\A([\w\.\+-]{2,})/
23
+ def valid_id_regex
24
+ /\A([\w\.\+-]{2,})/
25
+ end
24
26
  end
25
27
 
26
28
  end
@@ -3,17 +3,19 @@ class IdsPlease
3
3
 
4
4
  MASK = /fb\.me|fb\.com|facebook/i
5
5
 
6
- private
6
+ class << self
7
+ private
7
8
 
8
- def self.parse_link(link)
9
- query = CGI.parse(link.query) if link.query && !link.query.empty?
9
+ def parse_link(link)
10
+ query = CGI.parse(link.query) if link.query && !link.query.empty?
10
11
 
11
- if query && !query['id'].empty?
12
- query['id'].first
13
- elsif link.path =~ /\/pages\//
14
- link.path.split('/').last
15
- else
16
- link.path.split('/')[1]
12
+ if query && !query['id'].empty?
13
+ query['id'].first
14
+ elsif link.path =~ /\/pages\//
15
+ link.path.split('/').last
16
+ else
17
+ link.path.split('/')[1]
18
+ end
17
19
  end
18
20
  end
19
21
 
@@ -3,21 +3,23 @@ class IdsPlease
3
3
 
4
4
  MASK = /google/i
5
5
 
6
- def self.to_sym
7
- :google_plus
8
- end
6
+ class << self
7
+ def to_sym
8
+ :google_plus
9
+ end
9
10
 
10
- def self.parse(links)
11
- links.map { |l| parse_link(l) }.compact
12
- end
11
+ def parse(links)
12
+ links.map { |l| parse_link(l) }.compact
13
+ end
13
14
 
14
- private
15
+ private
15
16
 
16
- def self.parse_link(link)
17
- if matched = link.path.match(/\/(\+\w+)/)
18
- matched[1]
19
- elsif matched = link.path.match(/\/(\d{2,})/)
20
- matched[1]
17
+ def parse_link(link)
18
+ if matched = link.path.match(/\/(\+\w+)/)
19
+ matched[1]
20
+ elsif matched = link.path.match(/\/(\d{2,})/)
21
+ matched[1]
22
+ end
21
23
  end
22
24
  end
23
25
 
@@ -3,15 +3,17 @@ class IdsPlease
3
3
 
4
4
  MASK = /hi5/i
5
5
 
6
- private
6
+ class << self
7
+ private
7
8
 
8
- def self.parse_link(link)
9
- query = CGI.parse(link.query) if link.query && !link.query.empty?
9
+ def parse_link(link)
10
+ query = CGI.parse(link.query) if link.query && !link.query.empty?
10
11
 
11
- if query && !query['uid'].empty?
12
- query['uid'].first
13
- else
14
- link.path.split('/')[1]
12
+ if query && !query['uid'].empty?
13
+ query['uid'].first
14
+ else
15
+ link.path.split('/')[1]
16
+ end
15
17
  end
16
18
  end
17
19
 
@@ -3,18 +3,19 @@ class IdsPlease
3
3
 
4
4
  MASK = /linkedin/i
5
5
 
6
- private
6
+ class << self
7
+ private
7
8
 
8
- def self.parse_link(link)
9
- query = CGI.parse(link.query) if link.query && !link.query.empty?
9
+ def parse_link(link)
10
+ query = CGI.parse(link.query) if link.query && !link.query.empty?
10
11
 
11
- if query && !query['id'].empty?
12
- query['id'].first
13
- elsif link.path =~ /\/pub\//
14
- link.path.split('/')[2]
12
+ if query && !query['id'].empty?
13
+ query['id'].first
14
+ elsif link.path =~ /\/pub\//
15
+ link.path.split('/')[2]
16
+ end
15
17
  end
16
18
  end
17
19
 
18
-
19
20
  end
20
21
  end
@@ -3,13 +3,15 @@ class IdsPlease
3
3
 
4
4
  MASK = /livejournal/i
5
5
 
6
- private
6
+ class << self
7
+ private
7
8
 
8
- def self.parse_link(link)
9
- parsed = link.host.sub('.livejournal.com', '')
10
- parsed = link.host.split('.livejournal').first if parsed == link.host
11
- return if parsed == link.host
12
- parsed
9
+ def parse_link(link)
10
+ parsed = link.host.sub('.livejournal.com', '')
11
+ parsed = link.host.split('.livejournal').first if parsed == link.host
12
+ return if parsed == link.host
13
+ parsed
14
+ end
13
15
  end
14
16
 
15
17
  end
@@ -3,17 +3,19 @@ class IdsPlease
3
3
 
4
4
  MASK = /moikrug/i
5
5
 
6
- def self.parse(links)
7
- links.map do |link|
8
- next if link.host.sub('.moikrug.ru', '') == link.host
9
- parse_link(link)
10
- end.compact
11
- end
6
+ class << self
7
+ def parse(links)
8
+ links.map do |link|
9
+ next if link.host.sub('.moikrug.ru', '') == link.host
10
+ parse_link(link)
11
+ end.compact
12
+ end
12
13
 
13
- private
14
+ private
14
15
 
15
- def self.parse_link(link)
16
- link.host.sub('.moikrug.ru', '')
16
+ def parse_link(link)
17
+ link.host.sub('.moikrug.ru', '')
18
+ end
17
19
  end
18
20
 
19
21
  end
@@ -1,17 +1,19 @@
1
1
  class IdsPlease
2
2
  class Odnoklassniki < IdsPlease::BaseParser
3
3
 
4
- MASK = /odnoklassniki/i
4
+ MASK = /odnoklassniki|ok\.ru/i
5
5
 
6
- private
6
+ class << self
7
+ private
7
8
 
8
- def self.parse_link(link)
9
- if matched = link.path.match(/\/(\d{2,})/)
10
- matched[1]
11
- elsif link.path =~ /\/about\//
12
- link.path.split('/')[-2]
13
- elsif link.path.split('/').size >= 3
14
- link.path.split('/')[2]
9
+ def parse_link(link)
10
+ if matched = link.path.match(/\/(\d{2,})/)
11
+ matched[1]
12
+ elsif link.path =~ /\/about\//
13
+ link.path.split('/')[-2]
14
+ elsif link.path.split('/').size >= 3
15
+ link.path.split('/')[2]
16
+ end
15
17
  end
16
18
  end
17
19
 
@@ -3,10 +3,12 @@ class IdsPlease
3
3
 
4
4
  MASK = /reddit/i
5
5
 
6
- private
6
+ class << self
7
+ private
7
8
 
8
- def self.parse_link(link)
9
- link.path.split('/')[2]
9
+ def parse_link(link)
10
+ link.path.split('/')[2]
11
+ end
10
12
  end
11
13
 
12
14
  end
@@ -3,11 +3,13 @@ class IdsPlease
3
3
 
4
4
  MASK = /tumblr/i
5
5
 
6
- private
6
+ class << self
7
+ private
7
8
 
8
- def self.parse_link(link)
9
- return if link.host.sub('.tumblr.com', '') == link.host
10
- link.host.sub('.tumblr.com', '')
9
+ def parse_link(link)
10
+ return if link.host.sub('.tumblr.com', '') == link.host
11
+ link.host.sub('.tumblr.com', '')
12
+ end
11
13
  end
12
14
 
13
15
  end
@@ -3,14 +3,16 @@ class IdsPlease
3
3
 
4
4
  MASK = /twitter/i
5
5
 
6
- private
6
+ class << self
7
+ private
7
8
 
8
- def self.parse_link(link)
9
- if link.path =~ /%23!/
10
- id = link.path.sub(/\A\/%23!\//, '')
11
- id.split(/[\/\?#]/).first
12
- else
13
- link.path.split('/')[1]
9
+ def parse_link(link)
10
+ if link.path =~ /%23!/
11
+ id = link.path.sub(/\A\/%23!\//, '')
12
+ id.split(/[\/\?#]/).first
13
+ else
14
+ link.path.split('/')[1]
15
+ end
14
16
  end
15
17
  end
16
18
 
@@ -3,18 +3,20 @@ class IdsPlease
3
3
 
4
4
  MASK = /vk\.com|vkontakte/i
5
5
 
6
- def self.parse(links)
7
- links.map { |l| parse_link(l) }.compact
8
- end
6
+ class << self
7
+ def parse(links)
8
+ links.map { |l| parse_link(l) }.compact
9
+ end
9
10
 
10
- private
11
+ private
11
12
 
12
- def self.parse_link(link)
13
- if link.path =~ /id|club/
14
- id = link.path.sub(/\A\/id|\A\/club/, '')
15
- id.split(/[\/\?#]/).first
16
- else
17
- link.path.split('/')[1]
13
+ def parse_link(link)
14
+ if link.path =~ /id|club/
15
+ id = link.path.sub(/\A\/id|\A\/club/, '')
16
+ id.split(/[\/\?#]/).first
17
+ else
18
+ link.path.split('/')[1]
19
+ end
18
20
  end
19
21
  end
20
22
 
@@ -3,13 +3,15 @@ class IdsPlease
3
3
 
4
4
  MASK = /youtu\.be|youtube/i
5
5
 
6
- private
6
+ class << self
7
+ private
7
8
 
8
- def self.parse_link(link)
9
- if link.path =~ /channels|user/
10
- link.path.split('/')[2]
11
- else
12
- link.path.split('/')[1]
9
+ def parse_link(link)
10
+ if link.path =~ /channels|user/
11
+ link.path.split('/')[2]
12
+ else
13
+ link.path.split('/')[1]
14
+ end
13
15
  end
14
16
  end
15
17
 
data/lib/ids_please.rb CHANGED
@@ -22,7 +22,7 @@ require_relative 'ids_please/moikrug'
22
22
 
23
23
  class IdsPlease
24
24
 
25
- VERSION = '1.1.0'
25
+ VERSION = '1.1.1'
26
26
 
27
27
  attr_accessor :original, :unrecognized, :parsed
28
28
 
@@ -26,6 +26,7 @@ describe IdsPlease do
26
26
  https://youtube.com/channels/yb_acc
27
27
  http://tumblr-acc.tumblr.com
28
28
  http://odnoklassniki.com/profile/12341234/about
29
+ http://ok.ru/profile/12341234/about
29
30
  http://odnoklassniki.com/group/43214321/about?some=123
30
31
  http://moikrug-acc.moikrug.ru
31
32
  )
@@ -124,7 +125,7 @@ describe IdsPlease do
124
125
  end
125
126
 
126
127
  it 'recognizes odnoklassniki link' do
127
- expect(@recognizer.recognized[:odnoklassniki].count).to eq(2)
128
+ expect(@recognizer.recognized[:odnoklassniki].count).to eq(3)
128
129
  end
129
130
 
130
131
  it 'recognizes moikrug link' do
@@ -226,7 +227,7 @@ describe IdsPlease do
226
227
  end
227
228
 
228
229
  it 'get right id from odnoklassniki link' do
229
- expect(@recognizer.parsed[:odnoklassniki]).to eq(['12341234', '43214321'])
230
+ expect(@recognizer.parsed[:odnoklassniki].sort).to eq(['12341234', '43214321', '12341234'].sort)
230
231
  end
231
232
 
232
233
  it 'get right id from moikrug link' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ids_please
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - gazay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-01 00:00:00.000000000 Z
11
+ date: 2014-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake