data_magic 0.13 → 0.14

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.
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ === Version 0.14 / 2013-2-14
2
+ * Enhancements
3
+ * Added months_abbr translator
4
+ * Added day_of_week translator
5
+ * Added day_of_week_abbr translator
6
+ * Changed so translator methods are not call after mixing with class
7
+
1
8
  === Version 0.13 / 2013-2-7
2
9
  * Enhancements
3
10
  * Added add_translator method to DataMagic to allow custom translators to be added
@@ -94,6 +94,15 @@ Feature: Functionality of the data_magic gem
94
94
 
95
95
  Scenario: Getting a random month name
96
96
  Then the value for "some_month" should be a valid month
97
+
98
+ Scenario: Getting a random month abbreviation
99
+ Then the value for "month_abbr" should be a valid month abbreviation
100
+
101
+ Scenario: Getting a random day name
102
+ Then the value for "some_day" should be a valid day
103
+
104
+ Scenario: Getting a random day abbreviation
105
+ Then the value for "day_abbr" should be a valid day abbreviation
97
106
 
98
107
  Scenario: It should allow one to add new translator methods
99
108
  When I add the blah translator
@@ -103,6 +103,20 @@ Then /^the value for "(.*?)" should be a valid month$/ do |key|
103
103
  months.should include @data[key]
104
104
  end
105
105
 
106
+ Then /^the value for "(.*?)" should be a valid month abbreviation$/ do |key|
107
+ months = %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec]
108
+ months.should include @data[key]
109
+ end
110
+
111
+ Then /^the value for "(.*?)" should be a valid day$/ do |key|
112
+ days = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
113
+ days.should include @data[key]
114
+ end
115
+
116
+ Then /^the value for "(.*?)" should be a valid day abbreviation$/ do |key|
117
+ days = %w[Sun Mon Tue Wed Thu Fri Sat]
118
+ days.should include @data[key]
119
+ end
106
120
 
107
121
  When /^I add the blah translator$/ do
108
122
  module Blah
@@ -40,6 +40,9 @@ dm:
40
40
  5daysfromtoday: ~5.days_from_today
41
41
  5daysago: ~5.days_ago
42
42
  some_month: ~month
43
+ month_abbr: ~month_abbr
44
+ some_day: ~day_of_week
45
+ day_abbr: ~day_of_week_abbr
43
46
 
44
47
  dynamic:
45
48
  blah: ~blah
data/lib/data_magic.rb CHANGED
@@ -2,19 +2,15 @@ require 'data_magic/core_ext/string'
2
2
  require 'data_magic/core_ext/fixnum'
3
3
  require "data_magic/version"
4
4
  require "data_magic/translation"
5
- require "data_magic/date_translation"
6
5
  require 'yml_reader'
7
-
8
6
  require 'faker'
9
7
 
10
8
  module DataMagic
11
- include Translation
12
- include DateTranslation
13
9
  extend YmlReader
14
10
 
15
11
  def self.included(cls)
16
12
  translators.each do |translator|
17
- cls.send :include, translator
13
+ Translation.send :include, translator
18
14
  end
19
15
  end
20
16
 
@@ -30,12 +26,16 @@ module DataMagic
30
26
  data.each do |key, value|
31
27
  unless value.nil?
32
28
  next unless value.respond_to? '[]'
33
- data[key] = eval(value[1..-1]) if value[0,1] == "~"
29
+ data[key] = translate(value[1..-1]) if value[0,1] == "~"
34
30
  end
35
31
  end
36
32
  data
37
33
  end
38
34
 
35
+ def translate(value)
36
+ Translation.new.send :process, value
37
+ end
38
+
39
39
  class << self
40
40
  attr_accessor :yml
41
41
 
@@ -40,5 +40,34 @@ module DataMagic
40
40
  yesterday.strftime(format)
41
41
  end
42
42
  alias_method :dm_yesterday, :yesterday
43
+
44
+ #
45
+ # return a month
46
+ #
47
+ def month
48
+ randomize(Date::MONTHNAMES[1..-1])
49
+ end
50
+ alias_method :dm_month, :month
51
+
52
+ #
53
+ # return a month abbreviation
54
+ #
55
+ def month_abbr
56
+ randomize(Date::ABBR_MONTHNAMES[1..-1])
57
+ end
58
+ alias_method :dm_month_abbr, :month_abbr
59
+
60
+ #
61
+ # return a day of the week
62
+ #
63
+ def day_of_week
64
+ randomize(Date::DAYNAMES)
65
+ end
66
+ alias_method :dm_day_of_week, :day_of_week
67
+
68
+ def day_of_week_abbr
69
+ randomize(Date::ABBR_DAYNAMES)
70
+ end
71
+ alias_method :dm_day_of_week_abbr, :day_of_week_abbr
43
72
  end
44
73
  end
@@ -1,5 +1,9 @@
1
+ require 'data_magic/date_translation'
2
+
1
3
  module DataMagic
2
- module Translation
4
+ class Translation
5
+ include DateTranslation
6
+
3
7
  #
4
8
  # return a random name (first and last)
5
9
  #
@@ -243,12 +247,14 @@ module DataMagic
243
247
  end
244
248
  alias_method :dm_mask, :mask
245
249
 
246
- def month
247
- randomize(%w[January February March April May June July August September October November December])
248
- end
250
+
249
251
 
250
252
  private
251
253
 
254
+ def process(value)
255
+ eval value
256
+ end
257
+
252
258
  def remove_extension(phone)
253
259
  index = phone.index('x')
254
260
  phone = phone[0, (index-1)] if index
@@ -1,3 +1,3 @@
1
1
  module DataMagic
2
- VERSION = "0.13"
2
+ VERSION = "0.14"
3
3
  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.13'
4
+ version: '0.14'
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: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faker
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  segments:
126
126
  - 0
127
- hash: 2833217716898042459
127
+ hash: 2289410552337863128
128
128
  required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  segments:
135
135
  - 0
136
- hash: 2833217716898042459
136
+ hash: 2289410552337863128
137
137
  requirements: []
138
138
  rubyforge_project:
139
139
  rubygems_version: 1.8.24