r_fast_r_furious 2.0.0.pre → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -0
- data/README.md +7 -1
- data/lib/r_fast_r_furious.rb +30 -2
- data/lib/r_fast_r_furious/version.rb +1 -1
- data/r_fast_r_furious.gemspec +1 -0
- data/r_fast_r_furious.png +0 -0
- data/spec/fixtures/fast.js +16 -0
- data/spec/helper.rb +1 -0
- data/spec/r_fast_r_furious_spec.rb +47 -17
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f82f001ff88ef49397d772fa90a815cd63a0cc96
|
4
|
+
data.tar.gz: c9db2d937119ae895122f8f5864f1452f31df0dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47cc2ff0545fc503c011e649d9e32ed511b59a0b7269efeea333be6ea877bfed99f4566641132baf489ffcc5ad4d0cabf0118c464efb091c209c8290cf89ec63
|
7
|
+
data.tar.gz: 65216b89be9289672bd98290bd23db02d9556cdb4ad21327148670467e4af48a3c9fefb9b4b4ababd691182fe1fe436d4f89b3971f10de77abaebb6632e39d70
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# RFastRFurious
|
2
2
|
|
3
|
-
|
3
|
+
Easily validate movie titles from the fast and the furious saga
|
4
|
+
|
5
|
+
* Using and based upon [@alunny](https://github.com/alunny)'s [implementation](https://github.com/alunny/r_fast_r_furious)
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -22,6 +24,10 @@ Or install it yourself as:
|
|
22
24
|
RFastRFurious.check("Fast Five") # => true
|
23
25
|
RFastRFurious.check("The Sorrow and the Pity") # => false
|
24
26
|
|
27
|
+
## The Awesome Regex Explained
|
28
|
+
|
29
|
+
![http://www.debuggex.com/](r_fast_r_furious.png)
|
30
|
+
|
25
31
|
## Contributing
|
26
32
|
|
27
33
|
1. Fork it
|
data/lib/r_fast_r_furious.rb
CHANGED
@@ -1,7 +1,35 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
|
1
4
|
module RFastRFurious
|
2
|
-
|
3
|
-
|
5
|
+
SOURCE = "https://raw.github.com/alunny/r_fast_r_furious/master/fast.js"
|
6
|
+
REGEX = /^((T(he)(?=.*the)|2(?=.* 2)) )?Fast (Five|(((and t\3)|\2(?=.*s$)|&(?!.*:)) Furious(( (6|7))|: Tokyo Drift)?))$/
|
7
|
+
ERRORS = [LoadError, SocketError, Timeout::Error]
|
8
|
+
|
9
|
+
def offline_check(string)
|
4
10
|
!!REGEX.match(string)
|
5
11
|
end
|
12
|
+
module_function :offline_check
|
13
|
+
|
14
|
+
def check(string, url = SOURCE)
|
15
|
+
uri = URI.parse(SOURCE)
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
http.use_ssl = true
|
18
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
19
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
20
|
+
response = http.request(request)
|
21
|
+
content = response.body
|
22
|
+
cxt = if RUBY_PLATFORM == "java" # JRuby
|
23
|
+
require "rhino"
|
24
|
+
Rhino::Context.new
|
25
|
+
else
|
26
|
+
require "v8"
|
27
|
+
V8::Context.new
|
28
|
+
end
|
29
|
+
cxt.eval(content, "fast.js")
|
30
|
+
cxt["r_fast_r_furious"].call(string)
|
31
|
+
rescue *ERRORS
|
32
|
+
offline_check(string)
|
33
|
+
end
|
6
34
|
module_function :check
|
7
35
|
end
|
data/r_fast_r_furious.gemspec
CHANGED
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
(function (root, factory) {
|
2
|
+
if (typeof define === 'function' && define.amd) {
|
3
|
+
define(factory);
|
4
|
+
} else if (typeof exports === 'object') {
|
5
|
+
module.exports = factory();
|
6
|
+
} else {
|
7
|
+
// Browser globals (root is window)
|
8
|
+
root.r_fast_r_furious = factory();
|
9
|
+
}
|
10
|
+
}(this, function () {
|
11
|
+
var r_fast = /^((T(he)(?=.*the)|2(?=.* 2)) )?Fast (Five|(((and t\3)|\2(?=.*s$)|&(?!.*:)) Furious(( (6|7))|: Tokyo Drift)?))$/;
|
12
|
+
|
13
|
+
return function (str) {
|
14
|
+
return r_fast.test(str);
|
15
|
+
}
|
16
|
+
}));
|
data/spec/helper.rb
CHANGED
@@ -2,30 +2,60 @@ require 'helper'
|
|
2
2
|
|
3
3
|
RSpec.describe RFastRFurious do
|
4
4
|
|
5
|
+
AWESOME_MOVIES = [
|
6
|
+
"The Fast and the Furious",
|
7
|
+
"2 Fast 2 Furious",
|
8
|
+
"The Fast and the Furious: Tokyo Drift",
|
9
|
+
"Fast & Furious",
|
10
|
+
"Fast Five",
|
11
|
+
]
|
12
|
+
|
13
|
+
UNAWESOME_MOVIES = [
|
14
|
+
"The Sorrow and the Pity",
|
15
|
+
]
|
16
|
+
|
5
17
|
describe ".check" do
|
6
18
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
context "online" do
|
20
|
+
|
21
|
+
before do
|
22
|
+
stub_request(:get, "https://raw.github.com/alunny/r_fast_r_furious/master/fast.js").
|
23
|
+
to_return(:body => File.new(File.expand_path("../fixtures/fast.js", __FILE__)))
|
24
|
+
end
|
25
|
+
|
26
|
+
AWESOME_MOVIES.each do |title|
|
27
|
+
it "is true for \"#{title}\"" do
|
28
|
+
expect(RFastRFurious.check(title)).to be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
UNAWESOME_MOVIES.each do |title|
|
33
|
+
it "is false for \"#{title}\"" do
|
34
|
+
expect(RFastRFurious.check(title)).to be_false
|
35
|
+
end
|
18
36
|
end
|
37
|
+
|
19
38
|
end
|
20
39
|
|
21
|
-
|
22
|
-
|
23
|
-
|
40
|
+
context "offline" do
|
41
|
+
|
42
|
+
before do
|
43
|
+
stub_request(:get, "https://raw.github.com/alunny/r_fast_r_furious/master/fast.js").
|
44
|
+
to_raise(SocketError)
|
45
|
+
end
|
46
|
+
|
47
|
+
AWESOME_MOVIES.each do |title|
|
48
|
+
it "is true for \"#{title}\"" do
|
49
|
+
expect(RFastRFurious.check(title)).to be_true
|
50
|
+
end
|
51
|
+
end
|
24
52
|
|
25
|
-
|
26
|
-
|
27
|
-
|
53
|
+
UNAWESOME_MOVIES.each do |title|
|
54
|
+
it "is false for \"#{title}\"" do
|
55
|
+
expect(RFastRFurious.check(title)).to be_false
|
56
|
+
end
|
28
57
|
end
|
58
|
+
|
29
59
|
end
|
30
60
|
|
31
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r_fast_r_furious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Carey-Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1'
|
55
69
|
description: easily validate movie titles from the fast and the furious saga
|
56
70
|
email:
|
57
71
|
- tim@spork.in
|
@@ -69,6 +83,8 @@ files:
|
|
69
83
|
- lib/r_fast_r_furious.rb
|
70
84
|
- lib/r_fast_r_furious/version.rb
|
71
85
|
- r_fast_r_furious.gemspec
|
86
|
+
- r_fast_r_furious.png
|
87
|
+
- spec/fixtures/fast.js
|
72
88
|
- spec/helper.rb
|
73
89
|
- spec/r_fast_r_furious_spec.rb
|
74
90
|
homepage: https://github.com/halorgium/r_fast_r_furious
|
@@ -86,9 +102,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
102
|
version: '0'
|
87
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
104
|
requirements:
|
89
|
-
- - '
|
105
|
+
- - '>='
|
90
106
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
107
|
+
version: '0'
|
92
108
|
requirements: []
|
93
109
|
rubyforge_project:
|
94
110
|
rubygems_version: 2.0.0
|
@@ -96,5 +112,6 @@ signing_key:
|
|
96
112
|
specification_version: 4
|
97
113
|
summary: sometimes you just don't have enough time to read
|
98
114
|
test_files:
|
115
|
+
- spec/fixtures/fast.js
|
99
116
|
- spec/helper.rb
|
100
117
|
- spec/r_fast_r_furious_spec.rb
|