russian-reversal 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/russian-reversal.rb +9 -2
- data/spec/reverse.rb +10 -1
- metadata +3 -3
data/lib/russian-reversal.rb
CHANGED
@@ -6,6 +6,7 @@ require 'nokogiri'
|
|
6
6
|
|
7
7
|
module RussianReversal
|
8
8
|
REGEXP_NONWORD = /[^a-zA-Z-]/
|
9
|
+
VERBS_IGNORED = [ 'be', 'have', ]
|
9
10
|
|
10
11
|
def self.strip( s )
|
11
12
|
s.gsub( /\..*$/, '' )
|
@@ -14,8 +15,14 @@ module RussianReversal
|
|
14
15
|
def self.infinitive_of( verb )
|
15
16
|
doc = Nokogiri::HTML( open( "http://www.oxfordadvancedlearnersdictionary.com/dictionary/#{verb}" ) )
|
16
17
|
doc.search('div#relatedentries > ul > li').each do |e|
|
17
|
-
|
18
|
-
|
18
|
+
pos = e.at('span.pos')
|
19
|
+
if pos && pos.text.gsub( REGEXP_NONWORD, '' ) == 'verb'
|
20
|
+
v = e.at('span').children.first.text.strip
|
21
|
+
if VERBS_IGNORED.include?( v )
|
22
|
+
return nil
|
23
|
+
else
|
24
|
+
return v
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
data/spec/reverse.rb
CHANGED
@@ -11,6 +11,15 @@ describe 'RussianReversal' do
|
|
11
11
|
RussianReversal.reverse( 'The tanks decimated the platoon.' ).should.equal 'platoons decimate'
|
12
12
|
RussianReversal.reverse( 'The chef prepared a delicious meal.' ).should.equal 'meals prepare'
|
13
13
|
RussianReversal.reverse( 'The hungry lions were devouring a sheep.' ).should.equal 'sheep devour'
|
14
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'remains silent on parse failures' do
|
17
|
+
RussianReversal.reverse( 'He needs a NotARealEnglishWord' ).should.be.nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "doesn't activate on basic and auxiliary verbs" do
|
21
|
+
RussianReversal.reverse( "There won't be a video." ).should.be.nil
|
22
|
+
RussianReversal.reverse( "He has an object." ).should.be.nil
|
23
|
+
RussianReversal.reverse( "He was a criminal." ).should.be.nil
|
15
24
|
end
|
16
25
|
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: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pistos
|