Class: Chronomize

Inherits:
Object
  • Object
show all
Defined in:
lib/chronomize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, options = {}) ⇒ Chronomize

Returns a new instance of Chronomize.



8
9
10
11
# File 'lib/chronomize.rb', line 8

def initialize(date, options = {})
  self.date = date
  configure(options)
end

Instance Attribute Details

#backwardObject

Returns the value of attribute backward.



7
8
9
# File 'lib/chronomize.rb', line 7

def backward
  @backward
end

#dateObject

Returns the value of attribute date.



7
8
9
# File 'lib/chronomize.rb', line 7

def date
  @date
end

#date_formatObject

Returns the value of attribute date_format.



7
8
9
# File 'lib/chronomize.rb', line 7

def date_format
  @date_format
end

#forwardObject

Returns the value of attribute forward.



7
8
9
# File 'lib/chronomize.rb', line 7

def forward
  @forward
end

#todayObject

Returns the value of attribute today.



7
8
9
# File 'lib/chronomize.rb', line 7

def today
  @today
end

#tomorrowObject

Returns the value of attribute tomorrow.



7
8
9
# File 'lib/chronomize.rb', line 7

def tomorrow
  @tomorrow
end

#yesterdayObject

Returns the value of attribute yesterday.



7
8
9
# File 'lib/chronomize.rb', line 7

def yesterday
  @yesterday
end

Instance Method Details

#configure(options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chronomize.rb', line 13

def configure(options)
  self.date_format = options[:date_format] || :default
  self.yesterday = options.fetch(:yesterday) {I18n.translate('chronomize.yesterday', :default => 'yesterday')}
  self.today = options.fetch(:today) {I18n.translate('chronomize.today', :default => 'today')}
  self.tomorrow = options.fetch(:tomorrow) {I18n.translate('chronomize.tomorrow', :default => 'tomorrow')}
  self.backward = options.fetch(:previous) do
    # i18n doesn't support nil as default :/
    label = I18n.translate('chronomize.previous', :default => "")
    label.empty? ? nil : label
  end
  self.forward = options.fetch(:next) do
    label = I18n.translate('chronomize.next', :default => "")
    label.empty? ? nil : label
  end
end

#currentObject



33
34
35
# File 'lib/chronomize.rb', line 33

def current
  label_for day(0)
end

#nextObject



37
38
39
# File 'lib/chronomize.rb', line 37

def next
  label_for day(1), :forward
end

#previousObject



29
30
31
# File 'lib/chronomize.rb', line 29

def previous
  label_for day(-1), :backward
end