data_magic 0.11 → 0.12

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ === Version 0.12 / 2012-12-28
2
+ * Enhancements
3
+ * Added today translator
4
+ * Added tomorrow translator
5
+ * Added yesterday translator
6
+ * Added days_from_today to Fixnum to provide translator
7
+ * Added days_ago to Fixnum to provide translator
8
+
1
9
  === Version 0.11 / 2012-12-22
2
10
  * Enhancements
3
11
  * Added title translator
data/data_magic.gemspec CHANGED
@@ -16,9 +16,9 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  gem.require_paths = ["lib"]
18
18
 
19
- gem.add_dependency 'faker', '>= 1.0.1'
19
+ gem.add_dependency 'faker', '>= 1.1.2'
20
20
  gem.add_dependency 'yml_reader', '>= 0.2'
21
21
 
22
- gem.add_development_dependency 'rspec', '>= 2.6.0'
23
- gem.add_development_dependency 'cucumber', '>= 1.1.0'
22
+ gem.add_development_dependency 'rspec', '>= 2.12.0'
23
+ gem.add_development_dependency 'cucumber', '>= 1.2.0'
24
24
  end
@@ -82,3 +82,12 @@ Feature: Functionality of the data_magic gem
82
82
  Then the value for "mask" should begin with 3 numbers
83
83
  And the value for "mask" should have 3 upper case letters after a dash
84
84
  And the value for "mask" should end with 3 lower case letters
85
+
86
+ Scenario: Returning dates
87
+ Then the value for "today" should be today's date
88
+ And the value for "tomorrow" should be tomorrow's date
89
+ And the value for "yesterday" should be yesterday's date
90
+
91
+ Scenario: Specifying number of days from today
92
+ Then the value for "5daysfromtoday" should be five days from today
93
+ And the value for "5daysago" should be five days ago
@@ -73,3 +73,27 @@ end
73
73
  Then /^the value for "(.*?)" should include "(.*?)"$/ do |key, value|
74
74
  @data[key].should include value
75
75
  end
76
+
77
+ Then /^the value for "(.*?)" should be today\'s date$/ do |key|
78
+ @data[key].should == Date.today.strftime('%D')
79
+ end
80
+
81
+ Then /^the value for "(.*?)" should be tomorrow\'s date$/ do |key|
82
+ tomorrow = Date.today + 1
83
+ @data[key].should == tomorrow.strftime('%D')
84
+ end
85
+
86
+ Then /^the value for "(.*?)" should be yesterday\'s date$/ do |key|
87
+ yesterday = Date.today - 1
88
+ @data[key].should == yesterday.strftime('%D')
89
+ end
90
+
91
+ Then /^the value for "(.*?)" should be five days from today$/ do |key|
92
+ the_day = Date.today + 5
93
+ @data[key].should == the_day.strftime('%D')
94
+ end
95
+
96
+ Then /^the value for "(.*?)" should be five days ago$/ do |key|
97
+ the_day = Date.today - 5
98
+ @data[key].should == the_day.strftime('%D')
99
+ end
@@ -34,6 +34,11 @@ dm:
34
34
  range: ~randomize 1..5
35
35
  mask: ~mask "###-AAA_aaa"
36
36
  title: ~title
37
+ today: ~today
38
+ tomorrow: ~tomorrow
39
+ yesterday: ~yesterday
40
+ 5daysfromtoday: ~5.days_from_today
41
+ 5daysago: ~5.days_ago
37
42
 
38
43
  other:
39
44
  name: Cheezy
data/lib/data_magic.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  require 'data_magic/core_ext/string'
2
+ require 'data_magic/core_ext/fixnum'
2
3
  require "data_magic/version"
3
4
  require "data_magic/translation"
5
+ require "data_magic/date_translation"
4
6
  require 'yml_reader'
5
7
 
6
8
  require 'faker'
7
9
 
8
10
  module DataMagic
9
11
  include Translation
12
+ include DateTranslation
10
13
  extend YmlReader
11
14
 
12
15
  def data_for(key, additional={})
@@ -0,0 +1,11 @@
1
+ class Fixnum
2
+ def days_from_today(format = '%D')
3
+ the_day = Date.today + self
4
+ the_day.strftime(format)
5
+ end
6
+
7
+ def days_ago(format = '%D')
8
+ the_day = Date.today - self
9
+ the_day.strftime(format)
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ module DataMagic
2
+ module DateTranslation
3
+ #
4
+ # return today's date
5
+ #
6
+ # @param String the format to use for the date. Default is %D
7
+ #
8
+ # See http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-strftime
9
+ # for details of the formats
10
+ #
11
+ def today(format = '%D')
12
+ Date.today.strftime(format)
13
+ end
14
+
15
+ #
16
+ # return tomorrow's date
17
+ #
18
+ # @param String the format to use for the date. Default is %D
19
+ #
20
+ # See http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-strftime
21
+ # for details of the formats
22
+ #
23
+ def tomorrow(format = '%D')
24
+ tomorrow = Date.today + 1
25
+ tomorrow.strftime(format)
26
+ end
27
+
28
+ #
29
+ # return yesterday's date
30
+ #
31
+ # @param String the format to use for the date. Default is %D
32
+ #
33
+ # See http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-strftime
34
+ # for details of the formats
35
+ #
36
+ def yesterday(format = '%D')
37
+ yesterday = Date.today - 1
38
+ yesterday.strftime(format)
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module DataMagic
2
- VERSION = "0.11"
2
+ VERSION = "0.12"
3
3
  end
@@ -249,5 +249,36 @@ describe "DataMagic translations" do
249
249
  example.data_for('key').should have_field_value false
250
250
  end
251
251
  end
252
+
253
+ context "providing date values" do
254
+ it "should provide today's date" do
255
+ set_field_value '~today'
256
+ example.data_for('key').should have_field_value Date.today.strftime('%D')
257
+ end
258
+
259
+ it "should provide tomorrow's date" do
260
+ set_field_value '~tomorrow'
261
+ tomorrow = Date.today + 1
262
+ example.data_for('key').should have_field_value tomorrow.strftime('%D')
263
+ end
264
+
265
+ it "should provide yesterday's date" do
266
+ set_field_value '~yesterday'
267
+ yesterday = Date.today - 1
268
+ example.data_for('key').should have_field_value yesterday.strftime('%D')
269
+ end
270
+
271
+ it "should provide a date that is some number of days from now" do
272
+ set_field_value '~5.days_from_today'
273
+ the_date = Date.today + 5
274
+ example.data_for('key').should have_field_value the_date.strftime('%D')
275
+ end
276
+
277
+ it "should provide a date that is some number of days ago" do
278
+ set_field_value '~5.days_ago'
279
+ the_date = Date.today - 5
280
+ example.data_for('key').should have_field_value the_date.strftime('%D')
281
+ end
282
+ end
252
283
  end
253
284
  end
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.11'
4
+ version: '0.12'
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-12-22 00:00:00.000000000 Z
12
+ date: 2012-12-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faker
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.0.1
21
+ version: 1.1.2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.0.1
29
+ version: 1.1.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: yml_reader
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: 2.6.0
53
+ version: 2.12.0
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.6.0
61
+ version: 2.12.0
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: cucumber
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: 1.1.0
69
+ version: 1.2.0
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
- version: 1.1.0
77
+ version: 1.2.0
78
78
  description: Provides datasets to application stored in YAML files
79
79
  email:
80
80
  - jeff.morgan@leandog.com
@@ -102,7 +102,9 @@ 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/fixnum.rb
105
106
  - lib/data_magic/core_ext/string.rb
107
+ - lib/data_magic/date_translation.rb
106
108
  - lib/data_magic/translation.rb
107
109
  - lib/data_magic/version.rb
108
110
  - spec/lib/data_magic_spec.rb
@@ -122,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
124
  version: '0'
123
125
  segments:
124
126
  - 0
125
- hash: 4075926568841345413
127
+ hash: 722238677510975421
126
128
  required_rubygems_version: !ruby/object:Gem::Requirement
127
129
  none: false
128
130
  requirements:
@@ -131,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
133
  version: '0'
132
134
  segments:
133
135
  - 0
134
- hash: 4075926568841345413
136
+ hash: 722238677510975421
135
137
  requirements: []
136
138
  rubyforge_project:
137
139
  rubygems_version: 1.8.24