parsable 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dbda0cdf2f7beade2e6df252c90b65d4ac58b17
4
- data.tar.gz: 7d14957ad92713946d32d44383c17bfac1be6c5b
3
+ metadata.gz: 3da0e05d9c9f0396d90d101a98d427f62567941f
4
+ data.tar.gz: 3734d2108f2dff1f9da7e18a7ea8cb37936f8e67
5
5
  SHA512:
6
- metadata.gz: ad2d59f720cec99c17891b69a62f03b3199f916d5bb7e0e9e7d6b3c24a92ece2a2584756958193761419cc0f778fad53ba446ada7e67b8436df11f565abec124
7
- data.tar.gz: 6c777d157984a1ed707e453513dfc9b7ecb65a8cdef6db1c2fa3a6bf5ae9510f56b6b0739db950c2111babbcbb2c9619c1ee8cb4d41d6ee655492eb3a7ccdd2b
6
+ metadata.gz: d74ff881314e4a550b66a3b73d1c4f1526a1f29641085a11cbca7bad1d958ea557ce77a85b7cbde12adcb89f88ec9f764dbeea9ed20918660eb6db59c07ce531
7
+ data.tar.gz: 59ce7eb7e8a092b2762c371a40a84b4ef2f33c2d720cfc39c839573340c318b699d2e9562b1a1ab6a136a83c9860c3976122634f47924abc18d7681f38a2b966
@@ -1,7 +1,7 @@
1
1
  module Parsable
2
2
  class Parser
3
3
 
4
- REGEX = /\{{2}(\w*\.?\S[^\{\{]*)\}{2}/
4
+ REGEX = /\{{2}(\w*\.?\S[^\{\{]*?)\}{2}/
5
5
 
6
6
  attr_accessor :original_string, :strings
7
7
 
@@ -1,3 +1,3 @@
1
1
  module Parsable
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -1,67 +1,73 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Parsable::Parser do
4
+ let(:parser) { described_class.new(:string => string) }
4
5
 
5
6
  describe '#parse' do
7
+ subject { parser.parse }
8
+ let(:first) { subject.first }
6
9
 
7
10
  context "when no variables" do
11
+ let(:string) { "novariables" }
8
12
  it "returns empty" do
9
- parsed = Parsable::Parser.new(:string => "novariables").parse
10
- expect(parsed).to be_empty
13
+ expect(subject).to be_empty
11
14
  end
12
15
  end
13
16
 
14
17
  context "nil string" do
18
+ let(:string) { nil }
15
19
  it "returns empty" do
16
- parsed = Parsable::Parser.new(:string => nil).parse
17
- expect(parsed).to be_empty
20
+ expect(subject).to be_empty
18
21
  end
19
22
  end
20
23
 
21
24
  context 'when one variable' do
22
- before :each do
23
- @parsed = Parsable::Parser.new(:string => %(my+{{location.name}}@email.com)).parse.first
24
- end
25
+ let(:string) { %(my+{{location.name}}@email.com) }
26
+
25
27
  it "parses object name" do
26
- expect(@parsed.object).to eql('location')
28
+ expect(first.object).to eql('location')
27
29
  end
28
30
 
29
31
  it "parses attribute" do
30
- expect(@parsed.attribute).to eql('name')
32
+ expect(first.attribute).to eql('name')
31
33
  end
32
34
  end
33
35
 
34
36
  context 'when multiple variables' do
35
- before :each do
36
- @parsed = Parsable::Parser.new(:string => %(my+{{location.name}}@{{email.domain}}.com)).parse
37
- end
37
+ let(:string) { %(my+{{location.name}}@{{email.domain}}.com) }
38
38
 
39
39
  it "returns multiple strings" do
40
- expect(@parsed.size).to eql(2)
40
+ expect(subject.size).to eql(2)
41
41
  end
42
42
 
43
43
  it "parses object names" do
44
- expect(@parsed.first.object).to eql('location')
45
- expect(@parsed.last.object).to eql('email')
44
+ expect(subject.first.object).to eql('location')
45
+ expect(subject.last.object).to eql('email')
46
46
  end
47
47
 
48
48
  it "parses attributes" do
49
- expect(@parsed.first.attribute).to eql('name')
50
- expect(@parsed.last.attribute).to eql('domain')
49
+ expect(subject.first.attribute).to eql('name')
50
+ expect(subject.last.attribute).to eql('domain')
51
51
  end
52
52
  end
53
53
 
54
54
  context 'when remote object' do
55
- subject { Parsable::Parser.new(:string => %({{remote.http://google.com?query1=q1&query2=q2}}@email.com)).parse.first }
56
-
55
+ let(:string) { %({{remote.http://google.com?query1=q1&query2=q2}}@email.com) }
57
56
  it "parses object name" do
58
- expect(subject.object).to eql('remote')
57
+ expect(first.object).to eql('remote')
59
58
  end
60
59
 
61
60
  it "parses attribute" do
62
- expect(subject.attribute).to eql('http://google.com?query1=q1&query2=q2')
61
+ expect(first.attribute).to eql('http://google.com?query1=q1&query2=q2')
63
62
  end
64
63
  end
65
- end
66
64
 
65
+ context 'when the match has the potential to greedy match' do
66
+ let(:string) { %({{foo.bar}}some other text}}) }
67
+
68
+ it 'performs a non-greedy match' do
69
+ expect(first.attribute).to eq('bar')
70
+ end
71
+ end
72
+ end
67
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hubert Liu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-18 00:00:00.000000000 Z
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler