Class: Week
- Inherits:
-
Object
- Object
- Week
- Defined in:
- lib/sixarm_ruby_week.rb
Instance Attribute Summary (collapse)
-
- (Object) date
readonly
Returns the value of attribute date.
Class Method Summary (collapse)
-
+ (Object) now
Return the week that starts today.
-
+ (Object) parse(date_text)
Parse date text to a week.
Instance Method Summary (collapse)
-
- (Object) +(other)
Addition: week + other => week.
-
- (Object) -(other)
Subtraction: week - other => week or integer.
-
- (Object) <(other)
Return week1.date < week2.date.
-
- (Object) <=(other)
Return week1.date <= week2.date.
-
- (Object) <=>(other)
Return week1.date <=> week2.date.
-
- (Object) ==(other)
Return week1.date == week2.date.
-
- (Object) >(other)
Return week1.date > week2.date.
-
- (Object) >=(other)
Return week1.date >= week2.date.
-
- (Object) date_range
Return the range start_date..end_date.
-
- (Object) end_date
Return the end date of this week.
-
- (Boolean) eql?(other)
Return week1.date.eql? week2.date.
-
- (Object) hash
Return the hash for object comparison.
-
- (Boolean) include?(date)
Return true iif the week includes the date, i.e.
-
- (Week) initialize(date)
constructor
A new instance of Week.
-
- (Object) next
Return the next week, i.e.
-
- (Object) previous
Return the previous week, i.e.
-
- (Object) start_date
Return the start date of this week.
-
- (Object) to_s
Return date.to_s.
Constructor Details
- (Week) initialize(date)
A new instance of Week
13 14 15 |
# File 'lib/sixarm_ruby_week.rb', line 13 def initialize(date) @date = date end |
Instance Attribute Details
- (Object) date (readonly)
Returns the value of attribute date
11 12 13 |
# File 'lib/sixarm_ruby_week.rb', line 11 def date @date end |
Class Method Details
+ (Object) now
Return the week that starts today
30 31 32 |
# File 'lib/sixarm_ruby_week.rb', line 30 def self.now Week.new(Date.today) end |
+ (Object) parse(date_text)
Parse date text to a week.
40 41 42 |
# File 'lib/sixarm_ruby_week.rb', line 40 def self.parse(date_text) Week.new(Date.parse(date_text)) end |
Instance Method Details
- (Object) +(other)
Addition: week + other => week
Return a date object pointing other weeks after self. The other should be a numeric value.
120 121 122 123 124 125 126 |
# File 'lib/sixarm_ruby_week.rb', line 120 def +(other) if other.is_a? Numeric return Week.new(date + (other.to_i * 7)) else raise TypeError end end |
- (Object) -(other)
Subtraction: week - other => week or integer
If the other is a numeric value, return a week object pointing other weeks before self.
If the other is a week object, then return the difference between the two weeks.
146 147 148 149 150 151 152 153 154 |
# File 'lib/sixarm_ruby_week.rb', line 146 def -(other) if other.is_a? Numeric return Week.new(date - (other * 7)) elsif other.is_a? Week return ((self.date - other.date) / 7).round else raise TypeError end end |
- (Object) <(other)
Return week1.date < week2.date
82 83 84 |
# File 'lib/sixarm_ruby_week.rb', line 82 def <(other) self.date < other.date end |
- (Object) <=(other)
Return week1.date <= week2.date
89 90 91 |
# File 'lib/sixarm_ruby_week.rb', line 89 def <=(other) self.date <= other.date end |
- (Object) <=>(other)
Return week1.date <=> week2.date
75 76 77 |
# File 'lib/sixarm_ruby_week.rb', line 75 def <=>(other) return self.date <=> other.date end |
- (Object) ==(other)
Return week1.date == week2.date
61 62 63 |
# File 'lib/sixarm_ruby_week.rb', line 61 def ==(other) self.date == other.date end |
- (Object) >(other)
Return week1.date > week2.date
96 97 98 |
# File 'lib/sixarm_ruby_week.rb', line 96 def >(other) self.date > other.date end |
- (Object) >=(other)
Return week1.date >= week2.date
103 104 105 |
# File 'lib/sixarm_ruby_week.rb', line 103 def >=(other) self.date >= other.date end |
- (Object) date_range
Return the range start_date..end_date
206 207 208 |
# File 'lib/sixarm_ruby_week.rb', line 206 def date_range start_date..end_date end |
- (Object) end_date
Return the end date of this week. This is the same as week.date + 6 days
195 196 197 |
# File 'lib/sixarm_ruby_week.rb', line 195 def end_date @date + 6 end |
- (Boolean) eql?(other)
Return week1.date.eql? week2.date
68 69 70 |
# File 'lib/sixarm_ruby_week.rb', line 68 def eql?(other) self.date == other.date end |
- (Object) hash
Return the hash for object comparison.
This is simply the has of the date, which means that two week objects created with the same date will compare equally.
54 55 56 |
# File 'lib/sixarm_ruby_week.rb', line 54 def hash date.hash end |
- (Boolean) include?(date)
Return true iif the week includes the date, i.e. if the date is in start_date..end_date
218 219 220 |
# File 'lib/sixarm_ruby_week.rb', line 218 def include?(date) (start_date..end_date).include?(date) end |
- (Object) next
Return the next week, i.e. seven day later.
168 169 170 |
# File 'lib/sixarm_ruby_week.rb', line 168 def next return self + 1 end |
- (Object) previous
Return the previous week, i.e. seven day earlier.
161 162 163 |
# File 'lib/sixarm_ruby_week.rb', line 161 def previous return self - 1 end |
- (Object) start_date
Return the start date of this week. This is the same as week.date.
183 184 185 |
# File 'lib/sixarm_ruby_week.rb', line 183 def start_date @date end |
- (Object) to_s
Return date.to_s
20 21 22 |
# File 'lib/sixarm_ruby_week.rb', line 20 def to_s @date.to_s end |