stamp 0.1.4 → 0.1.5

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/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
+ .yardoc
4
+ doc
3
5
  pkg/*
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stamp (0.1.4)
4
+ stamp (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -9,37 +9,37 @@ Feature: Stamping a date
9
9
  Given the date September 8, 2011
10
10
  When I stamp the example "<example>"
11
11
  Then I produce "<output>"
12
- And I like turtles
12
+ And I like turtles
13
13
 
14
14
  Examples:
15
- | example | output |
16
- | January | September |
17
- | Jan | Sep |
18
- | Jan 1 | Sep 8 |
19
- | Jan 01 | Sep 08 |
20
- | Jan 10 | Sep 08 |
21
- | Jan 1, 1999 | Sep 8, 2011 |
22
- | Monday | Thursday |
23
- | Tue, Jan 1 | Thu, Sep 8 |
15
+ | example | output |
16
+ | January | September |
17
+ | Jan | Sep |
18
+ | Jan 1 | Sep 8 |
19
+ | Jan 01 | Sep 08 |
20
+ | Jan 10 | Sep 08 |
21
+ | Jan 1, 1999 | Sep 8, 2011 |
22
+ | Monday | Thursday |
23
+ | Tue, Jan 1 | Thu, Sep 8 |
24
24
  | Tuesday, January 1, 1999 | Thursday, September 8, 2011 |
25
- | 01/1999 | 09/2011 |
26
- | 01/01 | 09/08 |
27
- | 01/31 | 09/08 |
28
- | 01/99 | 09/11 |
29
- | 01/01/1999 | 09/08/2011 |
30
- | 12/31/99 | 09/08/11 |
31
- | 31/12 | 08/09 |
32
- | 31/12/99 | 08/09/11 |
33
- | 31-Jan-1999 | 08-Sep-2011 |
34
- | 1999-12-31 | 2011-09-08 |
35
- | DOB: 12-31-1999 | DOB: 09-08-2011 |
25
+ | 01/1999 | 09/2011 |
26
+ | 01/01 | 09/08 |
27
+ | 01/31 | 09/08 |
28
+ | 01/99 | 09/11 |
29
+ | 01/01/1999 | 09/08/2011 |
30
+ | 12/31/99 | 09/08/11 |
31
+ | 31/12 | 08/09 |
32
+ | 31/12/99 | 08/09/11 |
33
+ | 31-Jan-1999 | 08-Sep-2011 |
34
+ | 1999-12-31 | 2011-09-08 |
35
+ | DOB: 12-31-1999 | DOB: 09-08-2011 |
36
36
 
37
37
  @time
38
38
  Scenario Outline: Formatting times by example
39
- Given the time October 9, 2011 at 13:31:27
39
+ Given the time September 8, 2011 at 13:31:27
40
40
  When I stamp the example "<example>"
41
41
  Then I produce "<output>"
42
- And I like turtles
42
+ And I like turtles
43
43
 
44
44
  Examples:
45
45
  | example | output |
@@ -53,13 +53,25 @@ Feature: Stamping a date
53
53
  | 08:59:59 PM | 01:31:27 PM |
54
54
  | 23:59:59 | 13:31:27 |
55
55
 
56
+ @date
57
+ @time
58
+ Scenario Outline: Formatting dates and times by example
59
+ Given the time September 8, 2011 at 13:31:27
60
+ When I stamp the example "<example>"
61
+ Then I produce "<output>"
62
+ And I like turtles
63
+
64
+ Examples:
65
+ | example | output |
66
+ | Jan 1, 1999 8:59 am | Sep 8, 2011 1:31 pm |
67
+ | 08:59 AM 1999-12-31 | 01:31 PM 2011-09-08 |
68
+ | Date: Jan 1, 1999 Time: 8:59 am | Date: Sep 8, 2011 Time: 1:31 pm |
56
69
 
57
70
  Scenario: strftime directives just get passed through
58
71
  Given the date December 21, 2012
59
72
  When I stamp the example "John Cusack was in a movie about %b %d, %Y, but it wasn't very good."
60
73
  Then I produce "John Cusack was in a movie about Dec 21, 2012, but it wasn't very good."
61
74
 
62
-
63
75
  Scenario: Plain text just gets passed through
64
76
  Given the date June 1, 1926
65
77
  When I stamp the example "Marilyn Monroe was born on January 1, 1999."
@@ -77,7 +89,7 @@ Feature: Stamping a date
77
89
 
78
90
  @wip
79
91
  Scenario Outline: Examples that aren't supported yet
80
- Given the date October 9, 2011
92
+ Given the time September 8, 2011 at 13:31:27
81
93
  When I stamp the example "<example>"
82
94
  Then I produce "<output>"
83
95
 
data/lib/stamp.rb CHANGED
@@ -12,7 +12,7 @@ module Stamp
12
12
  TWO_DIGIT_REGEXP = /^\d{2}$/
13
13
  FOUR_DIGIT_REGEXP = /^\d{4}$/
14
14
 
15
- TIME_REGEXP = /^(\d{1,2})(:)(\d{2})(\s*)(:)?(\d{2})?(\s*)?([ap]m)?$/i
15
+ TIME_REGEXP = /(\d{1,2})(:)(\d{2})(\s*)(:)?(\d{2})?(\s*)?([ap]m)?/i
16
16
 
17
17
  MERIDIAN_LOWER_REGEXP = /^(a|p)m$/
18
18
  MERIDIAN_UPPER_REGEXP = /^(A|P)M$/
@@ -38,18 +38,27 @@ module Stamp
38
38
  '%M' => '%S'
39
39
  }
40
40
 
41
-
41
+ # Formats a date/time using a human-friendly example as a template.
42
+ #
43
+ # @param [String] example a human-friendly date/time example
44
+ # @return [String] the formatted date or time
45
+ #
46
+ # @example
47
+ # Date.new(2012, 12, 21).stamp("Jan 1, 1999") #=> "Dec 21, 2012"
42
48
  def stamp(example)
43
49
  strftime(strftime_format(example))
44
50
  end
45
-
46
51
  alias :stamp_like :stamp
47
52
  alias :format_like :stamp
48
53
 
49
- private
50
-
51
54
  # Transforms the given string with example dates/times to a format string
52
55
  # suitable for strftime.
56
+ #
57
+ # @param [String] example a human-friendly date/time example
58
+ # @return [String] a strftime-friendly format
59
+ #
60
+ # @example
61
+ # Date.today.strftime_format("Jan 1, 1999") #=> "%b %e, %Y"
53
62
  def strftime_format(example)
54
63
  # extract any substrings that look like times, like "23:59" or "8:37 am"
55
64
  before, time_example, after = example.partition(TIME_REGEXP)
@@ -72,6 +81,8 @@ module Stamp
72
81
  words.join
73
82
  end
74
83
 
84
+ private
85
+
75
86
  # Transforms tokens that look like date/time parts to strftime directives.
76
87
  def strftime_directives(tokens)
77
88
  previous_directive = nil
data/lib/stamp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stamp
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/stamp.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = ["jeremy@weiskotten.com"]
10
10
  s.homepage = "https://github.com/jeremyw/stamp"
11
11
  s.summary = %Q{Date and time formatting for humans.}
12
- s.description = %Q{Format dates and times based on examples, not arcane strftime directives.}
12
+ s.description = %Q{Format dates and times based on human-friendly examples, not arcane strftime directives.}
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stamp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 4
10
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jeremy Weiskotten
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-07-14 00:00:00 -04:00
17
+ date: 2011-07-16 00:00:00 -04:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,13 +38,12 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
47
44
  type: :development
48
45
  version_requirements: *id002
49
- description: Format dates and times based on examples, not arcane strftime directives.
46
+ description: Format dates and times based on human-friendly examples, not arcane strftime directives.
50
47
  email:
51
48
  - jeremy@weiskotten.com
52
49
  executables: []
@@ -59,6 +56,7 @@ files:
59
56
  - .gitignore
60
57
  - .rvmrc
61
58
  - .travis.yml
59
+ - .yardopts
62
60
  - Gemfile
63
61
  - Gemfile.lock
64
62
  - LICENSE.txt
@@ -86,7 +84,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
84
  requirements:
87
85
  - - ">="
88
86
  - !ruby/object:Gem::Version
89
- hash: 3
90
87
  segments:
91
88
  - 0
92
89
  version: "0"
@@ -95,14 +92,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
92
  requirements:
96
93
  - - ">="
97
94
  - !ruby/object:Gem::Version
98
- hash: 3
99
95
  segments:
100
96
  - 0
101
97
  version: "0"
102
98
  requirements: []
103
99
 
104
100
  rubyforge_project:
105
- rubygems_version: 1.6.2
101
+ rubygems_version: 1.3.7
106
102
  signing_key:
107
103
  specification_version: 3
108
104
  summary: Date and time formatting for humans.