Class: Tricle::Time
- Inherits:
-
Object
- Object
- Tricle::Time
- Defined in:
- lib/tricle/time.rb
Instance Attribute Summary collapse
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
-
#beginning_of_day ⇒ Object
delegate methods ##.
- #beginning_of_week ⇒ Object
- #beginning_of_week? ⇒ Boolean
- #day_of_week ⇒ Object
-
#initialize(time = nil) ⇒ Time
constructor
A new instance of Time.
Constructor Details
#initialize(time = nil) ⇒ Time
Returns a new instance of Time.
5 6 7 |
# File 'lib/tricle/time.rb', line 5 def initialize(time=nil) @time = time || ::Time.now end |
Instance Attribute Details
#time ⇒ Object (readonly)
Returns the value of attribute time.
3 4 5 |
# File 'lib/tricle/time.rb', line 3 def time @time end |
Class Method Details
.beginning_of_week ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/tricle/time.rb', line 30 def beginning_of_week if Date.respond_to?(:beginning_of_week) # Rails >= 4.0.2 # http://apidock.com/rails/v4.0.2/Date/beginning_of_week/class Date.beginning_of_week else :monday end end |
Instance Method Details
#beginning_of_day ⇒ Object
delegate methods ##
19 20 21 |
# File 'lib/tricle/time.rb', line 19 def beginning_of_day self.time.beginning_of_day end |
#beginning_of_week ⇒ Object
23 24 25 |
# File 'lib/tricle/time.rb', line 23 def beginning_of_week self.time.beginning_of_week end |
#beginning_of_week? ⇒ Boolean
13 14 15 |
# File 'lib/tricle/time.rb', line 13 def beginning_of_week? self.day_of_week == self.class.beginning_of_week end |
#day_of_week ⇒ Object
9 10 11 |
# File 'lib/tricle/time.rb', line 9 def day_of_week self.time.strftime('%A').downcase.to_sym end |