Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added today, tomorrow, and yesterday translators

  • Loading branch information...
commit 235f052a6e733d7a39ebd76eb8b43adca866f62d 1 parent 9751627
@cheezy authored
View
6 ChangeLog
@@ -1,3 +1,9 @@
+=== Version 0.12
+* Enhancements
+ * Added today translator
+ * Added tomorrow translator
+ * Added yesterday translator
+
=== Version 0.11 / 2012-12-22
* Enhancements
* Added title translator
View
7 features/data_magic.feature
@@ -82,3 +82,10 @@ Feature: Functionality of the data_magic gem
Then the value for "mask" should begin with 3 numbers
And the value for "mask" should have 3 upper case letters after a dash
And the value for "mask" should end with 3 lower case letters
+
+ Scenario: Returning dates
+ Then the value for "today" should be today's date
+ And the value for "tomorrow" should be tomorrow's date
+ And the value for "yesterday" should be yesterday's date
+
+
View
14 features/step_definitions/data_magic_steps.rb
@@ -73,3 +73,17 @@ class TestClass
Then /^the value for "(.*?)" should include "(.*?)"$/ do |key, value|
@data[key].should include value
end
+
+Then /^the value for "(.*?)" should be today\'s date$/ do |key|
+ @data[key].should == Date.today.strftime('%D')
+end
+
+Then /^the value for "(.*?)" should be tomorrow\'s date$/ do |key|
+ tomorrow = Date.today + 1
+ @data[key].should == tomorrow.strftime('%D')
+end
+
+Then /^the value for "(.*?)" should be yesterday\'s date$/ do |key|
+ yesterday = Date.today - 1
+ @data[key].should == yesterday.strftime('%D')
+end
View
3  features/yaml/example.yml
@@ -34,6 +34,9 @@ dm:
range: ~randomize 1..5
mask: ~mask "###-AAA_aaa"
title: ~title
+ today: ~today
+ tomorrow: ~tomorrow
+ yesterday: ~yesterday
other:
name: Cheezy
View
2  lib/data_magic.rb
@@ -1,12 +1,14 @@
require 'data_magic/core_ext/string'
require "data_magic/version"
require "data_magic/translation"
+require "data_magic/date_translation"
require 'yml_reader'
require 'faker'
module DataMagic
include Translation
+ include DateTranslation
extend YmlReader
def data_for(key, additional={})
View
41 lib/data_magic/date_translation.rb
@@ -0,0 +1,41 @@
+module DataMagic
+ module DateTranslation
+ #
+ # return today's date
+ #
+ # @param String the format to use for the date. Default is %D
+ #
+ # See http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-strftime
+ # for details of the formats
+ #
+ def today(format = '%D')
+ Date.today.strftime(format)
+ end
+
+ #
+ # return tomorrow's date
+ #
+ # @param String the format to use for the date. Default is %D
+ #
+ # See http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-strftime
+ # for details of the formats
+ #
+ def tomorrow(format = '%D')
+ tomorrow = Date.today + 1
+ tomorrow.strftime(format)
+ end
+
+ #
+ # return yesterday's date
+ #
+ # @param String the format to use for the date. Default is %D
+ #
+ # See http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-strftime
+ # for details of the formats
+ #
+ def yesterday(format = '%D')
+ yesterday = Date.today - 1
+ yesterday.strftime(format)
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.