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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59cd6698ba5d1e610f469986e66e765b4c50583b
4
- data.tar.gz: 00e04fcce40cc9d0eecc323d0aa02c352b48f586
3
+ metadata.gz: 752857ed8c0b2bd7de59d509e4a535935bca1a84
4
+ data.tar.gz: 126104d41811bda18dcba0062815757070b41a28
5
5
  SHA512:
6
- metadata.gz: 9e8d9bd6b4098c41657c3484457213684bbea32c7f19e78e0175e10fa31422f9334775b6ecc0ce6ea9d07432c243ee4a81ada3c92a7779a59b739df9e5e56600
7
- data.tar.gz: 40e2fcb76837dd970bbf0492bf333d881d18ad5876f628fa04b012b7eddd6a6c73cfc4bf9e890ba40f36ac42cb47e56edb8318613172ebe8adec3df2b6ac5929
6
+ metadata.gz: 43b82b6110908cdb21320619f478fe900749eb4e46873585843ca1380ce32dad92ceff7702089bf71653e65717172b36deb05b1c380aaba8b3089d3d376bfed2
7
+ data.tar.gz: 8cdcf2330039b366ae6cc700bd339cb3f35bb7d9b1b0740a7b2b89601922729beadd3d19e7cceba6abc91e9b3b48ba51bd4bfb8601e39a52f3f36450d47826d3
@@ -1,7 +1,9 @@
1
1
  class Hexpress
2
2
  CHARACTERS = [:word, :digit, :space]
3
- def initialize(&block)
4
- @hexpressions = []
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
- @hexpressions.map(&:to_s).join
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(hexpression)
88
+ def add(expression)
81
89
  tap do
82
- @hexpressions << hexpression
90
+ @expressions << expression
83
91
  end
84
92
  end
85
93
  end
@@ -1,5 +1,8 @@
1
1
  require "hexpress"
2
2
 
3
- def hexp(&block)
4
- Hexpress.new(&block)
3
+ class Object
4
+ def hex(&block)
5
+ Hexpress.new(&block)
6
+ end
7
+ alias_method :hexp, :hex
5
8
  end
@@ -1,9 +1,9 @@
1
1
  class Hexpress
2
2
  private
3
3
 
4
- def add_nested(hexpression, &block)
4
+ def add_nested(expression, &block)
5
5
  tap do
6
- @hexpressions << hexpression.new(&block)
6
+ @expressions << expression.new(&block)
7
7
  end
8
8
  end
9
9
 
@@ -1,5 +1,4 @@
1
1
  require "hexpress"
2
- require "pry"
3
2
 
4
3
  class Hexpress
5
4
  alias_method :startOfLine, :starting
@@ -1,3 +1,3 @@
1
1
  class Hexpress
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -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
@@ -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.0.0
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-04 00:00:00.000000000 Z
11
+ date: 2013-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler