Class: Tricle::Time

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#timeObject (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_weekObject



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_dayObject

delegate methods ##



19
20
21
# File 'lib/tricle/time.rb', line 19

def beginning_of_day
  self.time.beginning_of_day
end

#beginning_of_weekObject



23
24
25
# File 'lib/tricle/time.rb', line 23

def beginning_of_week
  self.time.beginning_of_week
end

#beginning_of_week?Boolean

Returns:

  • (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_weekObject



9
10
11
# File 'lib/tricle/time.rb', line 9

def day_of_week
  self.time.strftime('%A').downcase.to_sym
end