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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8b2bc0d21349f5184c7a82a56f0b7d0de15e449
4
- data.tar.gz: ad9f64e28df85deb7213ffb595d527da164f0049
3
+ metadata.gz: f82f001ff88ef49397d772fa90a815cd63a0cc96
4
+ data.tar.gz: c9db2d937119ae895122f8f5864f1452f31df0dd
5
5
  SHA512:
6
- metadata.gz: ccf07264e6ead97283b6e6dbc7b3ba8afa60dbc91227846ae458d1f58e2504f8dff767f8bb122b9f5601112ed1df436a9de3a233dca7ffc83010ae98d09ddb3c
7
- data.tar.gz: d18eca63b323710e12d90dddf6822425a2dd0c7bf8aeae6b3b62fd895b7bc447307eaf6edd2d8fc10a9c23d2559e02dc12329cdb4d06c680e6d9af8bc51224e7
6
+ metadata.gz: 47cc2ff0545fc503c011e649d9e32ed511b59a0b7269efeea333be6ea877bfed99f4566641132baf489ffcc5ad4d0cabf0118c464efb091c209c8290cf89ec63
7
+ data.tar.gz: 65216b89be9289672bd98290bd23db02d9556cdb4ad21327148670467e4af48a3c9fefb9b4b4ababd691182fe1fe436d4f89b3971f10de77abaebb6632e39d70
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ platforms :jruby do
4
+ gem 'therubyrhino'
5
+ end
6
+
7
+ platforms :ruby do
8
+ gem 'therubyracer'
9
+ end
10
+
3
11
  # Specify your gem's dependencies in r_fast_r_furious.gemspec
4
12
  gemspec
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # RFastRFurious
2
2
 
3
- easily validate movie titles from the fast and the furious saga
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
@@ -1,7 +1,35 @@
1
+ require "net/http"
2
+ require "uri"
3
+
1
4
  module RFastRFurious
2
- REGEX = /^((T(he)(?=.*the)|2(?=.* 2)) )?Fast (Five|(((and t\3)|\2(?=.*s$)|&(?!.*:)) Furious(( (6|7))|: Tokyo Drift)?))$/
3
- def check(string)
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
@@ -1,3 +1,3 @@
1
1
  module RFastRFurious
2
- VERSION = "2.0.0.pre"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec", ">= 2.14"
24
+ spec.add_development_dependency "webmock", ">= 1"
24
25
  end
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
+ }));
@@ -1,2 +1,3 @@
1
1
  require 'r_fast_r_furious'
2
2
  require 'rspec'
3
+ require 'webmock/rspec'
@@ -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
- AWESOME_MOVIES = [
8
- "The Fast and the Furious",
9
- "2 Fast 2 Furious",
10
- "The Fast and the Furious: Tokyo Drift",
11
- "Fast & Furious",
12
- "Fast Five",
13
- ]
14
-
15
- AWESOME_MOVIES.each do |title|
16
- it "is true for \"#{title}\"" do
17
- expect(RFastRFurious.check(title)).to be_true
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
- UNAWESOME_MOVIES = [
22
- "The Sorrow and the Pity",
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
- UNAWESOME_MOVIES.each do |title|
26
- it "is false for \"#{title}\"" do
27
- expect(RFastRFurious.check(title)).to be_false
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.pre
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-18 00:00:00.000000000 Z
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: 1.3.1
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