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_month ⇒ Object
- #beginning_of_month? ⇒ Boolean
- #beginning_of_week ⇒ Object
- #beginning_of_week? ⇒ Boolean
- #day_of_month ⇒ Object
- #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
42 43 44 45 46 47 48 49 50 |
# File 'lib/tricle/time.rb', line 42 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 ##
27 28 29 |
# File 'lib/tricle/time.rb', line 27 def beginning_of_day self.time.beginning_of_day end |
#beginning_of_month ⇒ Object
35 36 37 |
# File 'lib/tricle/time.rb', line 35 def beginning_of_month self.time.beginning_of_month end |
#beginning_of_month? ⇒ Boolean
21 22 23 |
# File 'lib/tricle/time.rb', line 21 def beginning_of_month? self.day_of_month == 1 end |
#beginning_of_week ⇒ Object
31 32 33 |
# File 'lib/tricle/time.rb', line 31 def beginning_of_week self.time.beginning_of_week end |
#beginning_of_week? ⇒ Boolean
17 18 19 |
# File 'lib/tricle/time.rb', line 17 def beginning_of_week? self.day_of_week == self.class.beginning_of_week end |
#day_of_month ⇒ Object
13 14 15 |
# File 'lib/tricle/time.rb', line 13 def day_of_month self.time.strftime('%-d').to_i 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 |