Class: Cal::DayName
- Inherits:
-
Object
- Object
- Cal::DayName
- Defined in:
- lib/cal/day_name.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#to_s ⇒ Object
readonly
Returns the value of attribute to_s.
-
#to_sym ⇒ Object
readonly
Returns the value of attribute to_sym.
Class Method Summary collapse
- .all(options = {}) ⇒ Object
- .friday ⇒ Object
- .monday ⇒ Object
- .saturday ⇒ Object
- .sunday ⇒ Object
- .thursday ⇒ Object
- .tuesday ⇒ Object
- .wednesday ⇒ Object
Instance Method Summary collapse
-
#initialize(symbol, string, position) ⇒ DayName
constructor
A new instance of DayName.
- #previous ⇒ Object
- #succ ⇒ Object (also: #next)
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
#position ⇒ Object (readonly)
Returns the value of attribute position.
55 56 57 |
# File 'lib/cal/day_name.rb', line 55 def position @position end |
#to_s ⇒ Object (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_sym ⇒ Object (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( = {}) if [:start_on] sunday_to_saturday.rotate(send([:start_on].to_s.downcase.to_sym).position - 1) else sunday_to_saturday end end |
.friday ⇒ Object
32 33 34 |
# File 'lib/cal/day_name.rb', line 32 def friday @friday ||= new :friday, 'Friday', 6 end |
.monday ⇒ Object
16 17 18 |
# File 'lib/cal/day_name.rb', line 16 def monday @monday ||= new :monday, 'Monday', 2 end |
.saturday ⇒ Object
36 37 38 |
# File 'lib/cal/day_name.rb', line 36 def saturday @saturday ||= new :saturday, 'Saturday', 7 end |
.sunday ⇒ Object
12 13 14 |
# File 'lib/cal/day_name.rb', line 12 def sunday @sunday ||= new :sunday, 'Sunday', 1 end |
.thursday ⇒ Object
28 29 30 |
# File 'lib/cal/day_name.rb', line 28 def thursday @thursday ||= new :thursday, 'Thursday', 5 end |
.tuesday ⇒ Object
20 21 22 |
# File 'lib/cal/day_name.rb', line 20 def tuesday @tuesday ||= new :tuesday, 'Tuesday', 3 end |
.wednesday ⇒ Object
24 25 26 |
# File 'lib/cal/day_name.rb', line 24 def wednesday @wednesday ||= new :wednesday, 'Wednesday', 4 end |
Instance Method Details
#previous ⇒ Object
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 |
#succ ⇒ Object 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 |