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 +4 -4
- data/lib/parsable/parser.rb +1 -1
- data/lib/parsable/version.rb +1 -1
- data/spec/parser_spec.rb +28 -22
- 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: 3da0e05d9c9f0396d90d101a98d427f62567941f
|
4
|
+
data.tar.gz: 3734d2108f2dff1f9da7e18a7ea8cb37936f8e67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d74ff881314e4a550b66a3b73d1c4f1526a1f29641085a11cbca7bad1d958ea557ce77a85b7cbde12adcb89f88ec9f764dbeea9ed20918660eb6db59c07ce531
|
7
|
+
data.tar.gz: 59ce7eb7e8a092b2762c371a40a84b4ef2f33c2d720cfc39c839573340c318b699d2e9562b1a1ab6a136a83c9860c3976122634f47924abc18d7681f38a2b966
|
data/lib/parsable/parser.rb
CHANGED
data/lib/parsable/version.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
23
|
-
|
24
|
-
end
|
25
|
+
let(:string) { %(my+{{location.name}}@email.com) }
|
26
|
+
|
25
27
|
it "parses object name" do
|
26
|
-
expect(
|
28
|
+
expect(first.object).to eql('location')
|
27
29
|
end
|
28
30
|
|
29
31
|
it "parses attribute" do
|
30
|
-
expect(
|
32
|
+
expect(first.attribute).to eql('name')
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
context 'when multiple variables' do
|
35
|
-
|
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(
|
40
|
+
expect(subject.size).to eql(2)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "parses object names" do
|
44
|
-
expect(
|
45
|
-
expect(
|
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(
|
50
|
-
expect(
|
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
|
-
|
56
|
-
|
55
|
+
let(:string) { %({{remote.http://google.com?query1=q1&query2=q2}}@email.com) }
|
57
56
|
it "parses object name" do
|
58
|
-
expect(
|
57
|
+
expect(first.object).to eql('remote')
|
59
58
|
end
|
60
59
|
|
61
60
|
it "parses attribute" do
|
62
|
-
expect(
|
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
|
+
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-
|
11
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|