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



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_dayObject

delegate methods ##



27
28
29
# File 'lib/tricle/time.rb', line 27

def beginning_of_day
  self.time.beginning_of_day
end

#beginning_of_monthObject



35
36
37
# File 'lib/tricle/time.rb', line 35

def beginning_of_month
  self.time.beginning_of_month
end

#beginning_of_month?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/tricle/time.rb', line 21

def beginning_of_month?
  self.day_of_month == 1
end

#beginning_of_weekObject



31
32
33
# File 'lib/tricle/time.rb', line 31

def beginning_of_week
  self.time.beginning_of_week
end

#beginning_of_week?Boolean

Returns:

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



13
14
15
# File 'lib/tricle/time.rb', line 13

def day_of_month
  self.time.strftime('%-d').to_i
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