Class: Cal::DayName

Inherits:
Object
  • Object
show all
Defined in:
lib/cal/day_name.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol, string, position) ⇒ DayName

Returns a new instance of DayName.



49
50
51
52
53
# File 'lib/cal/day_name.rb', line 49

def initialize(symbol, string, position)
  @to_sym = symbol
  @to_s = string
  @position = position
end

Instance Attribute Details

#positionObject (readonly)

Returns the value of attribute position.



55
56
57
# File 'lib/cal/day_name.rb', line 55

def position
  @position
end

#to_sObject (readonly)

Returns the value of attribute to_s.



55
56
57
# File 'lib/cal/day_name.rb', line 55

def to_s
  @to_s
end

#to_symObject (readonly)

Returns the value of attribute to_sym.



55
56
57
# File 'lib/cal/day_name.rb', line 55

def to_sym
  @to_sym
end

Class Method Details

.all(options = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/cal/day_name.rb', line 4

def all(options = {})
  if options[:start_on]
    sunday_to_saturday.rotate(send(options[:start_on].to_s.downcase.to_sym).position - 1)
  else
    sunday_to_saturday
  end
end

.fridayObject



32
33
34
# File 'lib/cal/day_name.rb', line 32

def friday
  @friday ||= new :friday, 'Friday', 6
end

.mondayObject



16
17
18
# File 'lib/cal/day_name.rb', line 16

def monday
  @monday ||= new :monday, 'Monday', 2
end

.saturdayObject



36
37
38
# File 'lib/cal/day_name.rb', line 36

def saturday
  @saturday ||= new :saturday, 'Saturday', 7
end

.sundayObject



12
13
14
# File 'lib/cal/day_name.rb', line 12

def sunday
  @sunday ||= new :sunday, 'Sunday', 1
end

.thursdayObject



28
29
30
# File 'lib/cal/day_name.rb', line 28

def thursday
  @thursday ||= new :thursday, 'Thursday', 5
end

.tuesdayObject



20
21
22
# File 'lib/cal/day_name.rb', line 20

def tuesday
  @tuesday ||= new :tuesday, 'Tuesday', 3
end

.wednesdayObject



24
25
26
# File 'lib/cal/day_name.rb', line 24

def wednesday
  @wednesday ||= new :wednesday, 'Wednesday', 4
end

Instance Method Details

#previousObject



65
66
67
68
69
# File 'lib/cal/day_name.rb', line 65

def previous
  self.class.all.detect do |day_name|
    day_name.position == (position > 1 ? position - 1 : 7)
  end
end

#succObject Also known as: next



57
58
59
60
61
# File 'lib/cal/day_name.rb', line 57

def succ
  self.class.all.detect do |day_name|
    day_name.position == (position < 7 ? position + 1 : 1)
  end
end