Class: Chronomize
- Inherits:
-
Object
- Object
- Chronomize
- Defined in:
- lib/chronomize.rb
Instance Attribute Summary collapse
-
#backward ⇒ Object
Returns the value of attribute backward.
-
#date ⇒ Object
Returns the value of attribute date.
-
#date_format ⇒ Object
Returns the value of attribute date_format.
-
#forward ⇒ Object
Returns the value of attribute forward.
-
#today ⇒ Object
Returns the value of attribute today.
-
#tomorrow ⇒ Object
Returns the value of attribute tomorrow.
-
#yesterday ⇒ Object
Returns the value of attribute yesterday.
Instance Method Summary collapse
- #configure(options) ⇒ Object
- #current ⇒ Object
-
#initialize(date, options = {}) ⇒ Chronomize
constructor
A new instance of Chronomize.
- #next ⇒ Object
- #previous ⇒ Object
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, = {}) self.date = date configure() end |
Instance Attribute Details
#backward ⇒ Object
Returns the value of attribute backward.
7 8 9 |
# File 'lib/chronomize.rb', line 7 def backward @backward end |
#date ⇒ Object
Returns the value of attribute date.
7 8 9 |
# File 'lib/chronomize.rb', line 7 def date @date end |
#date_format ⇒ Object
Returns the value of attribute date_format.
7 8 9 |
# File 'lib/chronomize.rb', line 7 def date_format @date_format end |
#forward ⇒ Object
Returns the value of attribute forward.
7 8 9 |
# File 'lib/chronomize.rb', line 7 def forward @forward end |
#today ⇒ Object
Returns the value of attribute today.
7 8 9 |
# File 'lib/chronomize.rb', line 7 def today @today end |
#tomorrow ⇒ Object
Returns the value of attribute tomorrow.
7 8 9 |
# File 'lib/chronomize.rb', line 7 def tomorrow @tomorrow end |
#yesterday ⇒ Object
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() self.date_format = [:date_format] || :default self.yesterday = .fetch(:yesterday) {I18n.translate('chronomize.yesterday', :default => 'yesterday')} self.today = .fetch(:today) {I18n.translate('chronomize.today', :default => 'today')} self.tomorrow = .fetch(:tomorrow) {I18n.translate('chronomize.tomorrow', :default => 'tomorrow')} self.backward = .fetch(:previous) do # i18n doesn't support nil as default :/ label = I18n.translate('chronomize.previous', :default => "") label.empty? ? nil : label end self.forward = .fetch(:next) do label = I18n.translate('chronomize.next', :default => "") label.empty? ? nil : label end end |
#current ⇒ Object
33 34 35 |
# File 'lib/chronomize.rb', line 33 def current label_for day(0) end |
#next ⇒ Object
37 38 39 |
# File 'lib/chronomize.rb', line 37 def next label_for day(1), :forward end |
#previous ⇒ Object
29 30 31 |
# File 'lib/chronomize.rb', line 29 def previous label_for day(-1), :backward end |