data_magic 0.9 → 0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +6 -1
- data/features/data_magic.feature +9 -0
- data/features/step_definitions/data_magic_steps.rb +25 -1
- data/features/yaml/example.yml +3 -0
- data/lib/data_magic.rb +1 -0
- data/lib/data_magic/core_ext/string.rb +5 -0
- data/lib/data_magic/translation.rb +30 -0
- data/lib/data_magic/version.rb +1 -1
- metadata +5 -4
data/ChangeLog
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
==- Version 0.10 / 2012-12-8
|
2
|
+
* Enhancements
|
3
|
+
* Added randomize translator to return random selection from Array or Range
|
4
|
+
* Added mask translator which accepts a mask. Will replace # with number, A with upper case letter, and a with lower case letter
|
5
|
+
|
6
|
+
=== Version 0.9 / 2012-8-18
|
2
7
|
* Enhancements
|
3
8
|
* Added name_prefix translator
|
4
9
|
* Added name_suffix translator
|
data/features/data_magic.feature
CHANGED
@@ -68,3 +68,12 @@ Feature: Functionality of the data_magic gem
|
|
68
68
|
Then the value for "name" should be "Wheezy"
|
69
69
|
And the value for "address" should be "999 Alergy Ave"
|
70
70
|
And the value for "email" should be "wheezy@example.com"
|
71
|
+
|
72
|
+
Scenario: Returning a randomly selected value from an array
|
73
|
+
Then the value for "random" should be either "Tom", "Dick", or "Harry"
|
74
|
+
And the value for "range" should be between 1 and 5
|
75
|
+
|
76
|
+
Scenario: Returning a value based on a mask
|
77
|
+
Then the value for "mask" should begin with 3 numbers
|
78
|
+
And the value for "mask" should have 3 upper case letters after a dash
|
79
|
+
And the value for "mask" should end with 3 lower case letters
|
@@ -41,7 +41,31 @@ Then /^the value for "(.+)" should exist$/ do |key|
|
|
41
41
|
@data[key].should_not be_nil
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
44
|
When /^I load the file "(.+)"$/ do |file_name|
|
46
45
|
DataMagic.load file_name
|
47
46
|
end
|
47
|
+
|
48
|
+
Then /^the value for "(.*?)" should be either "(.*?)", "(.*?)", or "(.*?)"$/ do |key, vala, valb, valc|
|
49
|
+
[vala, valb, valc].should include @data[key]
|
50
|
+
end
|
51
|
+
|
52
|
+
Then /^the value for "(.*?)" should be between (\d+) and (\d+)$/ do |key, low, high|
|
53
|
+
value = @data[key]
|
54
|
+
value.should >= low.to_i
|
55
|
+
value.should <= high.to_i
|
56
|
+
end
|
57
|
+
|
58
|
+
Then /^the value for "(.*?)" should begin with (\d+) numbers$/ do |key, num|
|
59
|
+
value = @data[key]
|
60
|
+
value[0,num.to_i].is_integer.should be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
Then /^the value for "(.*?)" should have (\d+) upper case letters after a dash$/ do |key, num|
|
64
|
+
value = @data[key]
|
65
|
+
value[4,num.to_i].upcase.should == value[4,3]
|
66
|
+
end
|
67
|
+
|
68
|
+
Then /^the value for "(.*?)" should end with (\d+) lower case letters$/ do |key, num|
|
69
|
+
value = @data[key]
|
70
|
+
value[-1 * num.to_i,num.to_i].downcase.should == value[-3,3]
|
71
|
+
end
|
data/features/yaml/example.yml
CHANGED
data/lib/data_magic.rb
CHANGED
@@ -161,5 +161,35 @@ module DataMagic
|
|
161
161
|
def phone_number
|
162
162
|
Faker::PhoneNumber.phone_number
|
163
163
|
end
|
164
|
+
|
165
|
+
#
|
166
|
+
# return a random value from an array or range
|
167
|
+
#
|
168
|
+
def randomize(value)
|
169
|
+
case value
|
170
|
+
when Array then value[rand(value.size)]
|
171
|
+
when Range then rand((value.last+1) - value.first) + value.first
|
172
|
+
else value
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
#
|
177
|
+
# return a value based on a mast
|
178
|
+
# The # character will be replaced with a number
|
179
|
+
# The A character will be replaced with an upper case letter
|
180
|
+
# The a character will be replaced with a lower case letter
|
181
|
+
#
|
182
|
+
def mask(value)
|
183
|
+
result = ''
|
184
|
+
value.each_char do |ch|
|
185
|
+
case ch
|
186
|
+
when '#' then result += randomize(0..9).to_s
|
187
|
+
when 'A' then result += ('A'..'Z').to_a[rand(26)]
|
188
|
+
when 'a' then result += ('a'..'z').to_a[rand(26)]
|
189
|
+
else result += ch
|
190
|
+
end
|
191
|
+
end
|
192
|
+
result
|
193
|
+
end
|
164
194
|
end
|
165
195
|
end
|
data/lib/data_magic/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.10'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08
|
12
|
+
date: 2012-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faker
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- features/yaml/another.yml
|
103
103
|
- features/yaml/example.yml
|
104
104
|
- lib/data_magic.rb
|
105
|
+
- lib/data_magic/core_ext/string.rb
|
105
106
|
- lib/data_magic/translation.rb
|
106
107
|
- lib/data_magic/version.rb
|
107
108
|
- spec/lib/data_magic_spec.rb
|
@@ -121,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
122
|
version: '0'
|
122
123
|
segments:
|
123
124
|
- 0
|
124
|
-
hash: -
|
125
|
+
hash: -1776216975269859243
|
125
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
127
|
none: false
|
127
128
|
requirements:
|
@@ -130,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
131
|
version: '0'
|
131
132
|
segments:
|
132
133
|
- 0
|
133
|
-
hash: -
|
134
|
+
hash: -1776216975269859243
|
134
135
|
requirements: []
|
135
136
|
rubyforge_project:
|
136
137
|
rubygems_version: 1.8.24
|