russian-reversal 1.0.4 → 1.0.5
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.
- data/lib/russian-reversal.rb +16 -9
- data/spec/reverse.rb +18 -2
- metadata +3 -3
data/lib/russian-reversal.rb
CHANGED
@@ -5,8 +5,9 @@ require 'open-uri'
|
|
5
5
|
require 'nokogiri'
|
6
6
|
|
7
7
|
module RussianReversal
|
8
|
-
REGEXP_NONWORD = /[^a-zA-Z-]/
|
9
|
-
VERBS_IGNORED = [ 'be', 'have', ]
|
8
|
+
REGEXP_NONWORD = /[^a-zA-Z -]/
|
9
|
+
VERBS_IGNORED = [ 'be', 'have', 'can', ]
|
10
|
+
NOUNS_IGNORED = [ 'it', 'him', 'her', 'them', 'me', 'you', 'us', 'this', 'that', 'these', 'those', ]
|
10
11
|
|
11
12
|
def self.strip( s )
|
12
13
|
s.gsub( /\..*$/, '' )
|
@@ -15,19 +16,25 @@ module RussianReversal
|
|
15
16
|
def self.infinitive_of( verb )
|
16
17
|
doc = Nokogiri::HTML( open( "http://www.oxfordadvancedlearnersdictionary.com/dictionary/#{verb}" ) )
|
17
18
|
doc.search('div#relatedentries > ul > li').each do |e|
|
18
|
-
|
19
|
-
if
|
20
|
-
|
21
|
-
if
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
pos_element = e.at('span.pos')
|
20
|
+
if pos_element
|
21
|
+
pos = pos_element.text.gsub( REGEXP_NONWORD, '' )
|
22
|
+
return if pos == 'modal verb' || pos == 'auxiliary verb'
|
23
|
+
if pos == 'verb'
|
24
|
+
v = e.at('span').children.first.text.strip
|
25
|
+
if VERBS_IGNORED.include?( v )
|
26
|
+
return
|
27
|
+
else
|
28
|
+
return v
|
29
|
+
end
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
29
34
|
|
30
35
|
def self.plural_of( noun )
|
36
|
+
return nil if NOUNS_IGNORED.include?( noun.downcase )
|
37
|
+
|
31
38
|
doc = Nokogiri::HTML( open( "http://www.oxfordadvancedlearnersdictionary.com/dictionary/#{noun}" ) )
|
32
39
|
|
33
40
|
plural_marker = doc.at('span.z_il')
|
data/spec/reverse.rb
CHANGED
@@ -17,9 +17,25 @@ describe 'RussianReversal' do
|
|
17
17
|
RussianReversal.reverse( 'He needs a NotARealEnglishWord' ).should.be.nil
|
18
18
|
end
|
19
19
|
|
20
|
-
it "doesn't activate on basic
|
20
|
+
it "doesn't activate on basic, auxiliary or modal verbs" do
|
21
21
|
RussianReversal.reverse( "There won't be a video." ).should.be.nil
|
22
22
|
RussianReversal.reverse( "He has an object." ).should.be.nil
|
23
23
|
RussianReversal.reverse( "He was a criminal." ).should.be.nil
|
24
|
+
RussianReversal.reverse( "He might be a criminal." ).should.be.nil
|
25
|
+
RussianReversal.reverse( "He ought to be good." ).should.be.nil
|
24
26
|
end
|
25
|
-
|
27
|
+
|
28
|
+
it "doesn't activate on pronouns or demonstratives" do
|
29
|
+
RussianReversal.reverse( 'They shot him' ).should.be.nil
|
30
|
+
RussianReversal.reverse( 'They shot her' ).should.be.nil
|
31
|
+
RussianReversal.reverse( 'They shot me' ).should.be.nil
|
32
|
+
RussianReversal.reverse( 'They shot you' ).should.be.nil
|
33
|
+
RussianReversal.reverse( 'They shot them' ).should.be.nil
|
34
|
+
RussianReversal.reverse( 'They shot us' ).should.be.nil
|
35
|
+
RussianReversal.reverse( 'They shot it' ).should.be.nil
|
36
|
+
RussianReversal.reverse( 'They shot this' ).should.be.nil
|
37
|
+
RussianReversal.reverse( 'They shot that' ).should.be.nil
|
38
|
+
RussianReversal.reverse( 'They shot these' ).should.be.nil
|
39
|
+
RussianReversal.reverse( 'They shot those' ).should.be.nil
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: russian-reversal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 5
|
10
|
+
version: 1.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pistos
|