hexpress 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hexpress.rb +13 -5
- data/lib/hexpress/main.rb +5 -2
- data/lib/hexpress/nested.rb +2 -2
- data/lib/hexpress/verbal_expressions.rb +0 -1
- data/lib/hexpress/version.rb +1 -1
- data/spec/lib/hexpress/main_spec.rb +10 -0
- data/spec/lib/hexpress/value/with_spec.rb +7 -0
- data/spec/lib/hexpress_spec.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 752857ed8c0b2bd7de59d509e4a535935bca1a84
|
4
|
+
data.tar.gz: 126104d41811bda18dcba0062815757070b41a28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43b82b6110908cdb21320619f478fe900749eb4e46873585843ca1380ce32dad92ceff7702089bf71653e65717172b36deb05b1c380aaba8b3089d3d376bfed2
|
7
|
+
data.tar.gz: 8cdcf2330039b366ae6cc700bd339cb3f35bb7d9b1b0740a7b2b89601922729beadd3d19e7cceba6abc91e9b3b48ba51bd4bfb8601e39a52f3f36450d47826d3
|
data/lib/hexpress.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
class Hexpress
|
2
2
|
CHARACTERS = [:word, :digit, :space]
|
3
|
-
|
4
|
-
|
3
|
+
attr_reader :expressions
|
4
|
+
|
5
|
+
def initialize(*expressions, &block)
|
6
|
+
@expressions = expressions
|
5
7
|
instance_exec(&block) if block_given?
|
6
8
|
end
|
7
9
|
|
@@ -70,16 +72,22 @@ class Hexpress
|
|
70
72
|
|
71
73
|
# This method returns the string version of the regexp.
|
72
74
|
def to_s
|
73
|
-
@
|
75
|
+
@expressions.map(&:to_s).join
|
76
|
+
end
|
77
|
+
|
78
|
+
# Takes an expression and returns the combination of the two expressions
|
79
|
+
# in a new Hexpress object.
|
80
|
+
def +(expression)
|
81
|
+
Hexpress.new(*expressions + expression.expressions)
|
74
82
|
end
|
75
83
|
|
76
84
|
private
|
77
85
|
|
78
86
|
# This method takes an hexpression and adds it to the hexpression queue
|
79
87
|
# while returning the main object.
|
80
|
-
def add(
|
88
|
+
def add(expression)
|
81
89
|
tap do
|
82
|
-
@
|
90
|
+
@expressions << expression
|
83
91
|
end
|
84
92
|
end
|
85
93
|
end
|
data/lib/hexpress/main.rb
CHANGED
data/lib/hexpress/nested.rb
CHANGED
data/lib/hexpress/version.rb
CHANGED
@@ -2,6 +2,16 @@ require "spec_helper"
|
|
2
2
|
require "hexpress/main"
|
3
3
|
|
4
4
|
describe Hexpress do
|
5
|
+
describe "hex" do
|
6
|
+
it "allow for a chain of methods" do
|
7
|
+
expect(hex.find("foo").to_r).to eq(/(foo)/)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "allow for a block of methods" do
|
11
|
+
expect(hex { find("foo") }.to_r).to eq(/(foo)/)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
describe "hexp" do
|
6
16
|
it "allow for a chain of methods" do
|
7
17
|
expect(hexp.find("foo").to_r).to eq(/(foo)/)
|
@@ -5,5 +5,12 @@ describe Hexpress::Value::With do
|
|
5
5
|
it "returns the string given" do
|
6
6
|
expect(described_class.new("foo").to_s).to eq("foo")
|
7
7
|
end
|
8
|
+
|
9
|
+
it "allows composing of multiple patterns" do
|
10
|
+
pattern1 = Hexpress.new.starting("foo")
|
11
|
+
pattern2 = Hexpress.new.ending("bar")
|
12
|
+
pattern3 = Hexpress.new.including(pattern1).with("1").including(pattern2)
|
13
|
+
expect(pattern3.to_r).to eq(/^foo1bar$/)
|
14
|
+
end
|
8
15
|
end
|
9
16
|
end
|
data/spec/lib/hexpress_spec.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Hexpress do
|
4
|
+
it "takes a list of expressions and turns them into a regex" do
|
5
|
+
expressions = [Hexpress::Value::With.new("foo"), Hexpress::Value::With.new("bar")]
|
6
|
+
pattern = Hexpress.new(*expressions)
|
7
|
+
expect(pattern.to_r).to eq(/foobar/)
|
8
|
+
end
|
9
|
+
|
4
10
|
it "takes a block and turns into a regex" do
|
5
11
|
pattern = Hexpress.new { find("foo") }
|
6
12
|
expect(pattern.to_r).to eq(/(foo)/)
|
@@ -70,4 +76,14 @@ describe Hexpress do
|
|
70
76
|
expect(Hexpress.new.anything.to_s).to eq('(?:.)*')
|
71
77
|
end
|
72
78
|
end
|
79
|
+
|
80
|
+
describe "#+" do
|
81
|
+
it "returns a combination of any number of expressions" do
|
82
|
+
pattern1 = Hexpress.new.with("foo")
|
83
|
+
pattern2 = Hexpress.new.with("bar")
|
84
|
+
pattern3 = Hexpress.new.with("bang")
|
85
|
+
pattern4 = pattern1 + pattern2 + pattern3
|
86
|
+
expect(pattern4.to_r).to eq(/foobarbang/)
|
87
|
+
end
|
88
|
+
end
|
73
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexpress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kurtis Rainbolt-Greene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|