semi 0.5.1 → 0.6.0
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/semi/variable.rb +8 -6
- data/lib/semi/variables/integer.rb +1 -1
- data/lib/semi/version.rb +1 -1
- data/spec/semi_variable_spec.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c505c74d8b3a177675808de5458154eb98e562f
|
4
|
+
data.tar.gz: 1fa3bdb689b9fa0a92bf959abcfaab0f40b8ae6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bcd802480e24a8d688217e2c86d1a3ac144a211ef1b641bedbe06e6c444d3cc34159299191754db7af87b647519eb23f63b3ce186559a6acf24a1f3dccecc8d
|
7
|
+
data.tar.gz: 6a12312e2f8b73f204f705f743338b8b320842e92f6a56676c97ca20470f8868cce36411cc35acbba7b5a52e57cafe6e1792380e2482fb6a49c7ff3f3deabd06
|
data/lib/semi/variable.rb
CHANGED
@@ -52,15 +52,17 @@ module Semi
|
|
52
52
|
|
53
53
|
|
54
54
|
def self.expand(val, dict)
|
55
|
+
unless ['Semi::Variables::String', 'String'].include? val.class.to_s
|
56
|
+
return val
|
57
|
+
end
|
58
|
+
|
55
59
|
check = true
|
56
60
|
while check
|
57
61
|
# Look for simple variable expansion
|
58
|
-
if
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
Regexp.last_match
|
63
|
-
val = $` + `$1` + $'
|
62
|
+
if match = /\$\{?(\w+)\}?/.match(val)
|
63
|
+
val = match.pre_match + dict[match[1].downcase] + match.post_match
|
64
|
+
elsif match = /\$\((.*)\)/.match(val)
|
65
|
+
val = match.pre_match + `#{match[1]} 2>/dev/null` + match.post_match
|
64
66
|
else
|
65
67
|
# no more matches... we must be done...
|
66
68
|
check = false
|
data/lib/semi/version.rb
CHANGED
data/spec/semi_variable_spec.rb
CHANGED
@@ -102,4 +102,23 @@ describe Semi::Variable do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
dictionary = {'one' => Semi::Variables::Integer.new(1),
|
106
|
+
'two' => Semi::Variables::Integer.new(2),
|
107
|
+
'alpha' => Semi::Variables::String.new('a'),
|
108
|
+
'beta' => Semi::Variables::String.new('b')}
|
109
|
+
|
110
|
+
[ #value, #expected
|
111
|
+
['abc123', 'abc123'],
|
112
|
+
['a$alpha', 'aa'],
|
113
|
+
['a$ALPHA', 'aa'],
|
114
|
+
['a${alpha}', 'aa'],
|
115
|
+
['a${ALPHA}', 'aa'],
|
116
|
+
['## $alpha / $beta ++', '## a / b ++'],
|
117
|
+
['## $ALPHA / $BETA ++', '## a / b ++'],
|
118
|
+
].each do |test|
|
119
|
+
it "#expand transforms '#{test[0]}' to '#{test[1]}'" do
|
120
|
+
expect(Semi::Variable::expand(test[0], dictionary)).to eql test[1]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
105
124
|
end
|