chronomize 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "chronomize"
6
- s.version = "0.0.2"
6
+ s.version = "0.0.3"
7
7
  s.authors = ["Katrina Owen"]
8
8
  s.email = ["katrina.owen@gmail.com"]
9
9
  s.homepage = ""
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_development_dependency "rspec"
21
21
  s.add_development_dependency "timecop"
22
- # s.add_runtime_dependency "i18n"
22
+ s.add_runtime_dependency "i18n"
23
23
  end
@@ -1,3 +1,4 @@
1
+ require 'i18n'
1
2
  require 'date'
2
3
  require 'extensions/date'
3
4
 
@@ -6,12 +7,23 @@ class Chronomize
6
7
  attr_accessor :date, :date_format, :yesterday, :today, :tomorrow, :backward, :forward
7
8
  def initialize(date, options = {})
8
9
  self.date = date
9
- self.date_format = options[:date_format] || "%B %-d, %Y"
10
- self.yesterday = options.fetch(:yesterday) { 'yesterday' }
11
- self.today = options.fetch(:today) { 'today' }
12
- self.tomorrow = options.fetch(:tomorrow) { 'tomorrow' }
13
- self.backward = options[:previous]
14
- self.forward = options[:next]
10
+ configure(options)
11
+ end
12
+
13
+ def configure(options)
14
+ self.date_format = options[:date_format] || :default
15
+ self.yesterday = options.fetch(:yesterday) {I18n.translate('chronomize.yesterday', :default => 'yesterday')}
16
+ self.today = options.fetch(:today) {I18n.translate('chronomize.today', :default => 'today')}
17
+ self.tomorrow = options.fetch(:tomorrow) {I18n.translate('chronomize.tomorrow', :default => 'tomorrow')}
18
+ self.backward = options.fetch(:previous) do
19
+ # i18n doesn't support nil as default :/
20
+ label = I18n.translate('chronomize.previous', :default => "")
21
+ label.empty? ? nil : label
22
+ end
23
+ self.forward = options.fetch(:next) do
24
+ label = I18n.translate('chronomize.next', :default => "")
25
+ label.empty? ? nil : label
26
+ end
15
27
  end
16
28
 
17
29
  def previous
@@ -26,6 +38,7 @@ class Chronomize
26
38
  label_for day(1), :forward
27
39
  end
28
40
 
41
+ private
29
42
  def day(n)
30
43
  date + n
31
44
  end
@@ -39,7 +52,7 @@ class Chronomize
39
52
  end
40
53
 
41
54
  def format(date)
42
- date.strftime(date_format)
55
+ I18n.localize(date, :format => date_format)
43
56
  end
44
57
 
45
58
  def chronicality(date)
@@ -10,6 +10,11 @@ describe Chronomize do
10
10
  let(:feb8) { Date.new(2012, 2, 8) }
11
11
  let(:feb9) { Date.new(2012, 2, 9) }
12
12
 
13
+ before(:each) do
14
+ en = {:date => {:month_names => [nil, 'January', 'February'], :formats => {:default => "%B %-d, %Y"}}}
15
+ I18n.backend.store_translations(:en, en)
16
+ end
17
+
13
18
  before(:each) { Timecop.freeze(feb7) }
14
19
  after(:each) { Timecop.return }
15
20
 
@@ -74,4 +79,35 @@ describe Chronomize do
74
79
  its(:current) { should eq('4.2.2012') }
75
80
  its(:next) { should eq('5.2.2012') }
76
81
  end
82
+
83
+ context "in alternate locale" do
84
+ before(:each) do
85
+ no = {:date => {:month_names => [nil, 'januar', 'februar'], :formats => {:my_custom_format => '%-d. %B %Y'}}}
86
+ I18n.backend.store_translations(:no, no)
87
+ I18n.locale = :no
88
+ end
89
+ after(:each) do
90
+ I18n.locale = nil
91
+ end
92
+
93
+ subject { Chronomize.new(feb4, :date_format => :my_custom_format) }
94
+
95
+ its(:previous) { should eq('3. februar 2012') }
96
+ its(:current) { should eq('4. februar 2012') }
97
+ its(:next) { should eq('5. februar 2012') }
98
+ end
99
+
100
+ context "with defaults" do
101
+ before(:each) do
102
+ en = {:chronomize => {:today => 'tdy', :tomorrow => 'tmrw', :yesterday => 'ystrdy', :previous => '<', :next => '>' }}
103
+ I18n.backend.store_translations(:en, en)
104
+ end
105
+
106
+ subject { Chronomize.new(feb7) }
107
+
108
+ its(:previous) { should eq('< ystrdy') }
109
+ its(:current) { should eq('tdy') }
110
+ its(:next) { should eq('tmrw >') }
111
+ end
112
+
77
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chronomize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70305360568220 !ruby/object:Gem::Requirement
16
+ requirement: &70294816684440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70305360568220
24
+ version_requirements: *70294816684440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: timecop
27
- requirement: &70305360567780 !ruby/object:Gem::Requirement
27
+ requirement: &70294816684000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,18 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70305360567780
35
+ version_requirements: *70294816684000
36
+ - !ruby/object:Gem::Dependency
37
+ name: i18n
38
+ requirement: &70294816683580 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70294816683580
36
47
  description: Creates labels for a window of dates, with knowledge about it's relationship
37
48
  to the current date.
38
49
  email: