strftime 1.0.0 → 2.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,14 @@
1
1
  # strftime
2
2
 
3
+ It's pronounced "strftime", not "strftime".
4
+
3
5
  With strftime you'll have descriptions of time format directives at your fingertips in Ruby.
4
6
 
5
- `Strftime::Directives` contains a hash of details about these directives.
7
+ `Strftime::Directive.all` contains an array of these directive objects
8
+ holding a key, description and example.
6
9
 
7
- Just use `Strftime::Directives['%M']` to get a description and example, or use the shorthand method `strfd('M')`
10
+ Just use `Strftime::Directives['%M']` to get a description and example, or use the shorthand method `strfd '%M'`
8
11
 
9
12
  Strftime::Directives['%M'].description #=> 'Minute of the hour'
10
13
 
11
- This might be useful for you, or for users of a system which are able to specify string formats for dates and times.
14
+ This might be useful for you, or for users of a system which are able to specify string formats for dates and times.
data/bin/strfd ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'date'
4
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/strftime.rb')
5
+
6
+ # If the argument appears like "%y" just output the description
7
+ # otherwise, find the format for the given date
8
+
9
+ given_date = ARGV[0]
10
+
11
+ if given_date
12
+ STDOUT.puts Strftime::InstructionSet.new(given_date).to_s
13
+ else
14
+ STDOUT.puts Strftime::Directive.all.sort
15
+ end
@@ -0,0 +1,47 @@
1
+ Feature: using the command line
2
+ As a command line user
3
+ I want to see the time parsing directives for a date
4
+ so that I may better use and understand time parsing
5
+
6
+ Scenario: Displaying all options
7
+ When I run "strfd"
8
+ Then the output should contain "%A"
9
+ And the output should contain "Saturday"
10
+ And the output should contain "English day of the week"
11
+ And the exit status should be 0
12
+
13
+ Scenario: Displaying complex directives
14
+ When I run "strfd 'February 18, 2007'"
15
+ Then the output should contain "%B %d, %Y"
16
+ And the exit status should be 0
17
+
18
+ Scenario: Four digit year directive
19
+ When I run "strfd '2010'"
20
+ Then the output should contain "%Y"
21
+
22
+ Scenario: Time zone offset directive
23
+ When I run "strfd '+0000'"
24
+ Then the output should contain "%z"
25
+
26
+ Scenario: Two digit directive
27
+ When I run "strfd '10'"
28
+ Then the output should contain "%g"
29
+ And the output should contain "%S"
30
+ And the output should contain "%H"
31
+ And the output should contain "%I"
32
+ And the output should contain "%U"
33
+ And the output should contain "%V"
34
+ And the output should contain "%k"
35
+ And the output should contain "%W"
36
+ And the output should contain "%m"
37
+ And the output should contain "%M"
38
+ And the output should contain "%C"
39
+ And the output should contain "%y"
40
+ And the output should contain "%d"
41
+
42
+ Scenario: One digit directive
43
+ When I run "strfd '3'"
44
+ Then the output should contain "%e"
45
+ Then the output should contain "%l"
46
+ Then the output should contain "%u"
47
+ Then the output should contain "%w"
@@ -0,0 +1,2 @@
1
+ require 'aruba'
2
+ require 'aruba/cucumber'
data/lib/kernel.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Kernel
2
+ def strfdirective(arg=nil)
3
+ return Strftime::Directive.all if arg == 'all'
4
+ if Strftime::Directive[arg]
5
+ Strftime::Directive[arg]
6
+ end
7
+ end
8
+ alias_method :strfd, :strfdirective
9
+ end
data/lib/strftime.rb CHANGED
@@ -1,67 +1,8 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/strftime/version'
3
+ require File.dirname(__FILE__) + '/strftime/directive'
4
+ require File.dirname(__FILE__) + '/strftime/directive_matchers'
5
+ require File.dirname(__FILE__) + '/strftime/instruction_set'
6
+ require File.dirname(__FILE__) + '/kernel'
1
7
  module Strftime
2
- Directives = Hash.new do |hash, key|
3
- mod = ('%' << key.to_s)
4
- hash[mod] if hash.keys.include?(mod)
5
- end
6
- Directives.merge!({
7
- '%a' => { :description => 'The abbreviated weekday name', :example => "Sun"},
8
- '%A' => { :description => 'The full weekday name', :example => "Sunday"},
9
- '%b' => { :description => 'The abbreviated month name', :example => "Jan"},
10
- '%B' => { :description => 'The full month name', :example => "January"},
11
- '%c' => { :description => 'The preferred local date and time representation'},
12
- '%C' => { :description => 'Century (20 in 2009)'},
13
- '%d' => { :description => 'Day of the month', :example => "01..31"},
14
- '%D' => { :description => 'Date (%m/%d/%y)'},
15
- '%e' => { :description => 'Day of the month, blank-padded', :example => "1..31"},
16
- '%F' => { :description => 'Equivalent to %Y-%m-%d (the ISO 8601 date format)'},
17
- '%h' => { :description => 'Equivalent to %b'},
18
- '%H' => { :description => 'Hour of the day, 24-hour clock', :example => "00..23"},
19
- '%I' => { :description => 'Hour of the day, 12-hour clock', :example => "01..12)"},
20
- '%j' => { :description => 'Day of the year', :example => "001..366"},
21
- '%k' => { :description => 'hour, 24-hour clock, blank-padded', :example => "0..23"},
22
- '%l' => { :description => 'hour, 12-hour clock, blank-padded', :example => "0..12"},
23
- '%L' => { :description => 'Millisecond of the second', :example => "000..999"},
24
- '%m' => { :description => 'Month of the year', :example => "01..12"},
25
- '%M' => { :description => 'Minute of the hour', :example => "00..59"},
26
- '%n' => { :description => 'Newline (\n)'},
27
- '%N' => { :description => 'Fractional seconds digits, default is 9 digits (nanosecond)
28
- %3N millisecond (3 digits)
29
- %6N microsecond (6 digits)
30
- %9N nanosecond (9 digits)'},
31
- '%p' => { :description => 'Meridian indicator', :example => "(``AM'' or ``PM'')"},
32
- '%P' => { :description => 'Meridian indicator', :example => "(``am'' or ``pm'')"},
33
- '%r' => { :description => 'time, 12-hour', :example => "same as %I:%M:%S %p"},
34
- '%R' => { :description => 'time, 24-hour', :example => "%H:%M"},
35
- '%s' => { :description => 'Number of seconds since 1970-01-01 00:00:00 UTC.'},
36
- '%S' => { :description => 'Second of the minute', :example => "00..60"},
37
- '%t' => { :description => 'Tab character', :example => "\t"},
38
- '%T' => { :description => 'time, 24-hour', :example => "%H:%M:%S"},
39
- '%u' => { :description => 'Day of the week as a decimal, Monday being 1.', :example => "1..7"},
40
- '%U' => { :description => 'Week number of the current year,
41
- starting with the first Sunday as the first
42
- day of the first week', :example => "00..53"},
43
- '%v' => { :description => 'VMS date', :example => "%e-%b-%Y"},
44
- '%V' => { :description => 'Week number of year according to ISO 8601', :example => "01..53"},
45
- '%W' => { :description => 'Week number of the current year,
46
- starting with the first Monday as the first
47
- day of the first week', :example => "00..53"},
48
- '%w' => { :description => 'Day of the week', :example => "Sunday is 0, 0..6"},
49
- '%x' => { :description => 'Preferred representation for the date alone, no time'},
50
- '%X' => { :description => 'Preferred representation for the time alone, no date'},
51
- '%y' => { :description => 'Year without a century', :example => "00..99"},
52
- '%Y' => { :description => 'Year with century'},
53
- '%z' => { :description => 'Time zone as hour offset from UTC (e.g. +0900)'},
54
- '%Z' => { :description => 'Time zone name'},
55
- '%%' => { :description => "Literal ``%'' character"}
56
- })
57
8
  end
58
-
59
- class Object
60
- def strfd(arg=nil)
61
- if arg
62
- Strftime::Directives[arg]
63
- else
64
- Strftime::Directives
65
- end
66
- end
67
- end
@@ -0,0 +1,261 @@
1
+ module Strftime
2
+ class Directive
3
+ attr_accessor :key
4
+ attr_accessor :description
5
+ attr_accessor :example
6
+ attr_accessor :matcher
7
+ attr_accessor :related
8
+
9
+ @all = []
10
+
11
+ def initialize(key, options={})
12
+ self.key = key
13
+ self.description = options[:description]
14
+ self.example = options[:example]
15
+ self.matcher = options[:matcher]
16
+ self.related = options[:related]
17
+ self.class.all << self
18
+ self
19
+ end
20
+ def <=>(directive)
21
+ key <=> directive.key
22
+ end
23
+ def to_s
24
+ %{ #{key} #=> #{example}
25
+ #{description}}
26
+ end
27
+ class << self
28
+ attr_accessor :all
29
+ attr_reader :default_collection
30
+
31
+ def [](key)
32
+ all.find{|d| d.key == key}
33
+ end
34
+
35
+ def matching(string)
36
+ Strftime::Directive.all.select{|d|
37
+ d.matcher.match(string)
38
+ }
39
+ end
40
+ end
41
+ @default_collection = {
42
+ '%A' => {:description => %{English day of the week},
43
+ :example => %{Saturday},
44
+ :matcher => Regexp.union(Date::DAYNAMES),
45
+ :related => ['%a']},
46
+
47
+ '%a' => {:description => %{Abbreviated English day of the week},
48
+ :example => %{Sat},
49
+ :matcher => Regexp.union(Date::ABBR_DAYNAMES),
50
+ :related => %w{%A %d %e}},
51
+
52
+ '%B' => {:description => %{English month of the year},
53
+ :example => %{December},
54
+ :matcher => Regexp.union(Date::MONTHNAMES.compact),
55
+ :related => %w{%b}},
56
+
57
+ '%b' => {:description => %{English month of the year},
58
+ :example => %{Dec},
59
+ :matcher => Regexp.union(Date::ABBR_MONTHNAMES.compact),
60
+ :related => %w{%B %v}},
61
+
62
+ '%C' => {:description => %{The century part of the year, zero-padded if necessary.},
63
+ :example => %{20},
64
+ :matcher => /\A\d\d\Z/,
65
+ :related => %w{%y %Y}},
66
+
67
+ '%c' => {:description => %{This prints the date and time in a way that looks like the default string representation of Time, but without the timezone. Equivalent to '%a %b %e %H:%M:%S %Y'},
68
+ :example => %{Sat Dec 31 13:22:33 2005},
69
+ :matcher => "(#{Date::ABBR_DAYNAMES.join('|')}) (#{Date::ABBR_MONTHNAMES.compact.join('|')}) [123]\\d [012]\\d:\\d{2}:\\d{2} \\d{4}",
70
+ :related => %w{%a %b %e %H %M %S %Y}},
71
+
72
+ '%D' => {:description => %{American-style short date format with two-digit year. Equivalent to "%m/%d/%y"},
73
+ :example => %{12/31/05},
74
+ :matcher => /[012]\d\/[012]\d\/\d{2}/,
75
+ :related => %w{%m %d %y %x}},
76
+
77
+ '%d' => {:description => %{Day of the month, zero-padded},
78
+ :example => %{03},
79
+ :matcher => /[01]\d/,
80
+ :related => %w{%e}},
81
+
82
+ '%e' => {:description => %{Day of the month, not zero-padded},
83
+ :example => %{3},
84
+ :matcher => /[123]?\d/,
85
+ :related => %w{%d %v}},
86
+
87
+ '%F' => {:description => %{Short date format with 4-digit year.; equivalent to "%Y-%m-%d"},
88
+ :example => %{2005-12-31},
89
+ :matcher => /\d{4}-[01]\d-[0123]\d/,
90
+ :related => %w{%Y %m %d %D}},
91
+
92
+ '%G' => {:description => %{Commercial year with century, zero-padded to a minimum of four digits and with a minus sign prepended for dates BCE. For the calendar year, use %Y)},
93
+ :example => %{2005},
94
+ :matcher => /\d{4}/,
95
+ :related => %w{%g %Y %y}},
96
+
97
+ '%g' => {:description => %{Year without century, zero-padded to two digits},
98
+ :example => %{05},
99
+ :matcher => /\d{2}/,
100
+ :related => %w{%G %Y %y}},
101
+
102
+ '%H' => {:description => %{Hour of the day, 24-hour clock, zero-padded to two digits},
103
+ :example => %{13},
104
+ :matcher => /[012]\d/,
105
+ :related => %w{%I}},
106
+
107
+ '%h' => {:description => %{Abbreviated month of the year; the same as "%b"},
108
+ :example => %{Dec},
109
+ :matcher => Regexp.union(Date::ABBR_MONTHNAMES.compact),
110
+ :related => %w{%b}},
111
+
112
+ '%I' => {:description => %{Hour of the day, 12-hour clock, zero-padded to two digits},
113
+ :example => %{01},
114
+ :matcher => /[01]\d/,
115
+ :related => %w{%H %l}},
116
+
117
+ '%j' => {:description => %{Julian day of the year, padded to three digits (from 001 to 366)},
118
+ :example => %{365},
119
+ :matcher => /\d{3}/,
120
+ :related => %w{}},
121
+
122
+ '%k' => {:description => %{Hour of the day, 24-hour clock, not zero-padded; like %H but with no padding},
123
+ :example => %{13},
124
+ :matcher => /\d?\d/,
125
+ :related => %w{%H}},
126
+
127
+ '%l' => {:description => %{Hour of the day, 12-hour clock, not zero-padded; like %I but with no padding},
128
+ :example => %{1},
129
+ :matcher => /\d?\d/,
130
+ :related => %w{%I}},
131
+
132
+ '%M' => {:description => %{Minute of the hour, padded to two digits},
133
+ :example => %{22},
134
+ :matcher => /\d{2}/,
135
+ :related => %w{}},
136
+
137
+ '%m' => {:description => %{Month of the year, padded to two digits},
138
+ :example => %{12},
139
+ :matcher => /\d{2}/,
140
+ :related => %w{}},
141
+
142
+ '%n' => {:description => %{A newline; don't use this; just put a newline in the formatting string},
143
+ :example => %{\n},
144
+ :matcher => /.+/m,
145
+ :related => %w{}},
146
+
147
+ '%P' => {:description => %{Lowercase meridian indicator ("am" or "pm")},
148
+ :example => %{pm},
149
+ :matcher => /am|pm/,
150
+ :related => %w{%p}},
151
+
152
+ '%p' => {:description => %{Upper meridian indicator. Like %P, except gives "AM" or "PM"; yes, the uppercase P gives the lowercase meridian, and vice versa},
153
+ :example => %{PM},
154
+ :matcher => /PM|AM/,
155
+ :related => %w{%P}},
156
+
157
+ '%R' => {:description => %{Short 24-hour time format; equivalent to "%H:%M"},
158
+ :example => %{13:22},
159
+ :matcher => /[012]\d:\d{2}/,
160
+ :related => %w{}},
161
+
162
+ '%r' => {:description => %{Long 12-hour time format; equivalent to "%I:%M:%S %p"},
163
+ :example => %{01:22:33 PM},
164
+ :matcher => /[01]\d:\d{2}:\d{2} (AM|PM)/,
165
+ :related => %w{}},
166
+
167
+ '%S' => {:description => %{Second of the minute, zero-padded to two digits},
168
+ :example => %{33},
169
+ :matcher => /\d{2}/,
170
+ :related => %w{}},
171
+
172
+ '%s' => {:description => %{Seconds since the Unix epoch},
173
+ :example => %{1136053353},
174
+ :matcher => /\d+/,
175
+ :related => %w{}},
176
+
177
+ '%T' => {:description => %{Long 24-hour time format; equivalent to "%H:%M:%S"},
178
+ :example => %{13:22:33},
179
+ :matcher => /[012]\d:\d{2}:\d{2}/,
180
+ :related => %w{%X}},
181
+
182
+ '%t' => {:description => %{A tab; don't use this; just put a tab in the formatting string},
183
+ :example => %{\t},
184
+ :matcher => /\Z\A/,
185
+ :related => %w{}},
186
+
187
+ '%U' => {:description => %{Calendar week number of the year: assumes that the first week of the year starts on the first Sunday; if a date comes before the first Sunday of the year, it's counted as part of "week zero" and "00" is returned},
188
+ :example => %{52},
189
+ :matcher => /\d{2}/,
190
+ :related => %w{}},
191
+
192
+ '%u' => {:description => %{Commercial weekday of the year, from 1 to 7, with Monday being day 1},
193
+ :example => %{6},
194
+ :matcher => /[1-7]/,
195
+ :related => %w{}},
196
+
197
+ '%V' => {:description => %{Commercial week number of the year},
198
+ :example => %{52},
199
+ :matcher => /\d{2}/,
200
+ :related => %w{%W}},
201
+
202
+ '%W' => {:description => %{The same as %V, but if a date is before the first Monday of the year, it's counted as part of "week zero" and "00" is returned},
203
+ :example => %{52},
204
+ :matcher => /\d{2}/,
205
+ :related => %w{%V}},
206
+
207
+ '%w' => {:description => %{Calendar day of the week, from 0 to 6, with Sunday being day 0},
208
+ :example => %{6},
209
+ :matcher => /\A[0-6]\Z/,
210
+ :related => %w{}},
211
+
212
+ '%X' => {:description => %{Preferred representation for the time; equivalent to "%H:%M:%S"},
213
+ :example => %{13:22:33},
214
+ :matcher => /[012]\d:\d{2}:\d{2}/,
215
+ :related => %w{%H %M %S %T}},
216
+
217
+ '%x' => {:description => %{Preferred representation for the date; equivalent to "%m/%d/%y"},
218
+ :example => %{12/31/05},
219
+ :matcher => /[012]\d\/[012]\d\/\d{2}/,
220
+ :related => %w{%m %d %y %D}},
221
+
222
+ '%Y' => {:description => %{Year with century, zero-padded to four digits and with a minus sign prepended for dates BCE},
223
+ :example => %{2005},
224
+ :matcher => /-?\d{4}/,
225
+ :related => %w{%y}},
226
+
227
+ '%y' => {:description => %{Year without century, zero-padded to two digits},
228
+ :example => %{05},
229
+ :matcher => /\A\d{2}\Z/,
230
+ :related => %w{%Y}},
231
+
232
+ '%Z' => {:description => %{The timezone abbreviation (Time) or GMT offset (Date). Date will use "Z" instead of "+0000" if a time is in GMT},
233
+ :example => %{"GMT" for Time, "Z" for Date},
234
+ :matcher => Regexp.new(Regexp.union(Date::Format::ZONES.sort_by{|z| z[0].length}.reverse.collect{|f| f[0]}).source,true),
235
+ :related => %w{%z}},
236
+
237
+ '%z' => {:description => %{The timezone as a GMT offset},
238
+ :example => %{+0000},
239
+ :matcher => /\A\\+\d{4}\Z/,
240
+ :related => %w{}},
241
+
242
+ '%%' => {:description => %{A literal percent sign},
243
+ :example => %{%},
244
+ :matcher => /\A%\Z/,
245
+ :related => %w{}},
246
+
247
+ '%v' => {:description => %{European-style date format with month abbreviation; equivalent to "%e-%b-%Y"},
248
+ :example => %{31-Dec-2005},
249
+ :matcher => Regexp.new("[123]?\\d-(#{Date::ABBR_MONTHNAMES.compact.join('|')})-\\d{4}"),
250
+ :related => %w{%e %b %Y}},
251
+
252
+ '%+' => {:description => %{Prints a Dateobject as though it were a Timeobject converted to a string; like %c, but includes the timezone information; equivalent to "%a %b %e %H:%M:%S %Z %Y"},
253
+ :example => %{Sat Dec 31 13:22:33 Z 2005},
254
+ :matcher => Regexp.new("#{Regexp.union(Date::ABBR_DAYNAMES)}\ #{Regexp.union(Date::ABBR_MONTHNAMES.compact)}\ [123]?\\d\ [012]\\d:\\d{2}:\\d{2}\ #{Regexp.new(Regexp.union(Date::Format::ZONES.sort_by{|z| z[0].length}.reverse.collect{|f| f[0]}).source,true).source}\\d{4}"),
255
+ :related => %w{%a %b %e %H %M %S %Z %Y}}
256
+ }.each do |k,v|
257
+ Strftime::Directive.new(k, v)
258
+ end
259
+ @default_collection = all
260
+ end
261
+ end
@@ -0,0 +1,7 @@
1
+ module Strftime
2
+ module DirectiveMatchers
3
+ MONTHNAMES_REGEXP = Regexp.new('('<<Date::MONTHNAMES.compact.join('|')<<')')
4
+ TIMEZONE_OFFSET_REGEXP = /\+\d{4}/
5
+ FOUR_DIGIT_YEAR_REGEXP = /\d{4}/
6
+ end
7
+ end
@@ -0,0 +1,46 @@
1
+ module Strftime
2
+ class InstructionSet
3
+ include Strftime::DirectiveMatchers
4
+ attr_reader :example
5
+ attr_writer :example
6
+ attr_reader :instructions
7
+ attr_writer :instructions
8
+ def initialize(given)
9
+ self.example = given
10
+ self.instructions = []
11
+ test_date = given.dup
12
+
13
+ # Single replacements
14
+ test_date.gsub!(MONTHNAMES_REGEXP,'%B')
15
+ test_date.gsub!(TIMEZONE_OFFSET_REGEXP,'%z')
16
+ test_date.gsub!(FOUR_DIGIT_YEAR_REGEXP,'%Y')
17
+
18
+ # 2 digit options
19
+ two_digit_directives = Strftime::Directive.all.select{|d|
20
+ d.example.match(/^\d{2}$/) rescue false
21
+ }
22
+ test_date.scan(/\d\d/).each do |found|
23
+ two_digit_directives.each do |directive|
24
+ self.instructions << test_date.sub(Regexp.new(found),directive.key)
25
+ end
26
+ end
27
+ one_character_directives = Strftime::Directive.all.select{|d|
28
+ d.example.match(/^[^%\W]{1}$/) rescue false
29
+ }
30
+ test_date.scan(/\d/).each do |found|
31
+ one_character_directives.each do |directive|
32
+ self.instructions << test_date.sub(Regexp.new(found),directive.key)
33
+ end
34
+ end
35
+ self.instructions << test_date if self.instructions.empty?
36
+
37
+ self.instructions.map!{|i| %{#{i} #=> #{Time.now.strftime(i)}}}
38
+ end
39
+
40
+ def to_s
41
+ content = 'Using the current time as the formatting date:'
42
+ self.instructions.join('
43
+ ')
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module Strftime
2
- VERSION = "1.0.0"
3
- end
2
+ VERSION = "2.0.0.alpha"
3
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe Strftime::Directive do
4
+ context '.matching' do
5
+ it 'should return all Directives that match the given string' do
6
+ Strftime::Directive.all = Strftime::Directive.default_collection
7
+ debugger
8
+ Strftime::Directive.matching('+1234').length.should == 1
9
+ end
10
+ end
11
+ context '.initialize' do
12
+ it 'should require a key' do
13
+ lambda{ Strftime::Directive.new }.should raise_error
14
+ end
15
+ it 'should set the first argument to the key' do
16
+ d = Strftime::Directive.new('%A')
17
+ d.key.should == '%A'
18
+ end
19
+ it 'should set the description from the given :description' do
20
+ d = Strftime::Directive.new('%B', :description => 'B directive')
21
+ d.description.should == 'B directive'
22
+ end
23
+ it 'should set the example from the given :example' do
24
+ d = Strftime::Directive.new('%C', :example => 'some format display')
25
+ d.example.should == 'some format display'
26
+ end
27
+ it "should set the matcher to a regular expression which matches it's replaceable text" do
28
+ d = Strftime::Directive.new('%D', :matcher => /ZOMG/)
29
+ d.matcher.should == /ZOMG/
30
+ end
31
+ end
32
+ context '.all=' do
33
+ it 'should set the collection of Strftime::Directive objects' do
34
+ Strftime::Directive.all.size.should be > 0
35
+ Strftime::Directive.all = []
36
+ Strftime::Directive.all.size.should == 0
37
+ end
38
+ end
39
+ context '.all' do
40
+ it 'should return a collection of all Strftime::Directive objects' do
41
+ directives = []
42
+ Strftime::Directive.all = []
43
+ directives << Strftime::Directive.new('%ZZ')
44
+ Strftime::Directive.all.should =~ directives
45
+ end
46
+ end
47
+ context '.default_collection' do
48
+ it 'should return the standard collection of Strftime::Directive objects' do
49
+ defaults = Strftime::Directive.default_collection
50
+ end
51
+ it 'should not be settable' do
52
+ lambda{ Strftime::Directive.default_collection = [] }.should raise_error(NoMethodError)
53
+ end
54
+ end
55
+ context '.[]' do
56
+ it 'should return a Directive with the key of the given argument' do
57
+ q = Strftime::Directive.new('%q')
58
+ Strftime::Directive['%q'].should == q
59
+ end
60
+ end
61
+ context '#<=>' do
62
+ it 'should compare the key to the given directive key' do
63
+ a = Strftime::Directive.new('%a')
64
+ b = Strftime::Directive.new('%b')
65
+ (a <=> b).should == -1
66
+ end
67
+ end
68
+ context '#to_s' do
69
+ it 'should output formatted contents' do
70
+ c = Strftime::Directive.new('%c', :description => 'Test sample.', :example => 'output something!')
71
+ c.to_s.should == ' %c #=> output something!
72
+ Test sample.'
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Strftime::InstructionSet do
4
+ context '.initialize' do
5
+ Strftime::Directive.all = Strftime::Directive.default_collection
6
+ it 'should require an example string' do
7
+ lambda{ Strftime::InstructionSet.new }.should raise_error
8
+ end
9
+ it 'should have a collection of instructions' do
10
+ Array.should === Strftime::InstructionSet.new('test').instructions
11
+ end
12
+ end
13
+
14
+ context '#to_s' do
15
+ it 'should output all instructions joined by a new line' do
16
+ test_set = Strftime::InstructionSet.new('January 01')
17
+ test_set.to_s.should == test_set.instructions.join('
18
+ ')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'strftime'
3
+
4
+ Rspec.configure do |c|
5
+ c.mock_with :rspec
6
+ end
data/strftime.gemspec CHANGED
@@ -16,18 +16,22 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
-
19
+
20
+ s.add_development_dependency('rspec', '~> 2.3.0')
21
+ s.add_development_dependency('aruba', '~> 0.3.2')
22
+
20
23
  s.post_install_message = %{
21
24
  Thanks for installing strftime. You can use these methods to
22
25
  better understand the formats used in Date and Time strftime
23
-
24
- Strftime::Directives #=> a full hash of directives
25
- Strftime::Directives['%y'] #=> a hash of description and
26
- # optional example value
27
-
28
- Strftime::Directives['y'] #=> optionally exclude the %
29
-
30
- strfd #=> shorthand to get directives
31
- strfd('y') #=> shorthand to get details
26
+
27
+ Strftime::Directive.all #=> a full array of directives
28
+ Strftime::Directive['%y'] #=> a Strftime::Directive with
29
+ # a key of the given argument
30
+
31
+ Strftime::Directive.default_collection #=> standard directives
32
+ # unchanged by your code
33
+
34
+ strfd #=> shorthand to get directives
35
+ strfd('%y') #=> shorthand to get details
32
36
  }
33
37
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strftime
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: -1851332194
5
+ prerelease: true
6
6
  segments:
7
- - 1
7
+ - 2
8
8
  - 0
9
9
  - 0
10
- version: 1.0.0
10
+ - alpha
11
+ version: 2.0.0.alpha
11
12
  platform: ruby
12
13
  authors:
13
14
  - Jim Gay
@@ -15,15 +16,46 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-11-04 00:00:00 -04:00
19
+ date: 2011-01-14 00:00:00 -05:00
19
20
  default_executable:
20
- dependencies: []
21
-
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rspec
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 2
33
+ - 3
34
+ - 0
35
+ version: 2.3.0
36
+ type: :development
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: aruba
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 23
47
+ segments:
48
+ - 0
49
+ - 3
50
+ - 2
51
+ version: 0.3.2
52
+ type: :development
53
+ version_requirements: *id002
22
54
  description: Convenient list of strftime format directives
23
55
  email:
24
56
  - jim@saturnflyer.com
25
- executables: []
26
-
57
+ executables:
58
+ - strfd
27
59
  extensions: []
28
60
 
29
61
  extra_rdoc_files: []
@@ -32,16 +64,26 @@ files:
32
64
  - .gitignore
33
65
  - Gemfile
34
66
  - LICENSE
35
- - README
67
+ - README.md
36
68
  - Rakefile
69
+ - bin/strfd
70
+ - features/possible_options_for_date.feature
71
+ - features/support/env.rb
72
+ - lib/kernel.rb
37
73
  - lib/strftime.rb
74
+ - lib/strftime/directive.rb
75
+ - lib/strftime/directive_matchers.rb
76
+ - lib/strftime/instruction_set.rb
38
77
  - lib/strftime/version.rb
78
+ - spec/lib/strftime/directive_spec.rb
79
+ - spec/lib/strftime/instruction_set_spec.rb
80
+ - spec/spec_helper.rb
39
81
  - strftime.gemspec
40
82
  has_rdoc: true
41
83
  homepage: http://rubygems.org/gems/strftime
42
84
  licenses: []
43
85
 
44
- post_install_message: "\n Thanks for installing strftime. You can use these methods to\n better understand the formats used in Date and Time strftime\n \n Strftime::Directives #=> a full hash of directives\n Strftime::Directives['%y'] #=> a hash of description and \n # optional example value\n \n Strftime::Directives['y'] #=> optionally exclude the %\n \n strfd #=> shorthand to get directives\n strfd('y') #=> shorthand to get details\n "
86
+ post_install_message: "\n Thanks for installing strftime. You can use these methods to\n better understand the formats used in Date and Time strftime\n\n Strftime::Directive.all #=> a full array of directives\n Strftime::Directive['%y'] #=> a Strftime::Directive with\n # a key of the given argument\n\n Strftime::Directive.default_collection #=> standard directives\n # unchanged by your code\n\n strfd #=> shorthand to get directives\n strfd('%y') #=> shorthand to get details\n "
45
87
  rdoc_options: []
46
88
 
47
89
  require_paths:
@@ -58,12 +100,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
100
  required_rubygems_version: !ruby/object:Gem::Requirement
59
101
  none: false
60
102
  requirements:
61
- - - ">="
103
+ - - ">"
62
104
  - !ruby/object:Gem::Version
63
- hash: 3
105
+ hash: 25
64
106
  segments:
65
- - 0
66
- version: "0"
107
+ - 1
108
+ - 3
109
+ - 1
110
+ version: 1.3.1
67
111
  requirements: []
68
112
 
69
113
  rubyforge_project:
@@ -71,5 +115,9 @@ rubygems_version: 1.3.7
71
115
  signing_key:
72
116
  specification_version: 3
73
117
  summary: Convenient list of strftime format directives
74
- test_files: []
75
-
118
+ test_files:
119
+ - features/possible_options_for_date.feature
120
+ - features/support/env.rb
121
+ - spec/lib/strftime/directive_spec.rb
122
+ - spec/lib/strftime/instruction_set_spec.rb
123
+ - spec/spec_helper.rb