Class: Rotation::Topic
- Inherits:
-
Object
- Object
- Rotation::Topic
- Defined in:
- lib/rotation/topic.rb
Instance Attribute Summary collapse
-
#candidates ⇒ Object
Returns the value of attribute candidates.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#first ⇒ Object
Returns the value of attribute first.
-
#name ⇒ Object
Returns the value of attribute name.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
Instance Method Summary collapse
- #cycle(unit_delta) ⇒ Object
-
#initialize(topic_name, params) ⇒ Topic
constructor
A new instance of Topic.
- #responsible(date = Date.today) ⇒ Object
- #responsible_index(date) ⇒ Object
- #week_delta(d1, d2) ⇒ Object
Constructor Details
#initialize(topic_name, params) ⇒ Topic
Returns a new instance of Topic.
5 6 7 8 9 10 11 |
# File 'lib/rotation/topic.rb', line 5 def initialize(topic_name, params) @name = topic_name @duration = params["duration"] @start_date = params["start_date"] @first = params["first"] @candidates = params["candidates"] end |
Instance Attribute Details
#candidates ⇒ Object
Returns the value of attribute candidates.
3 4 5 |
# File 'lib/rotation/topic.rb', line 3 def candidates @candidates end |
#duration ⇒ Object
Returns the value of attribute duration.
3 4 5 |
# File 'lib/rotation/topic.rb', line 3 def duration @duration end |
#first ⇒ Object
Returns the value of attribute first.
3 4 5 |
# File 'lib/rotation/topic.rb', line 3 def first @first end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/rotation/topic.rb', line 3 def name @name end |
#start_date ⇒ Object
Returns the value of attribute start_date.
3 4 5 |
# File 'lib/rotation/topic.rb', line 3 def start_date @start_date end |
Instance Method Details
#cycle(unit_delta) ⇒ Object
22 23 24 |
# File 'lib/rotation/topic.rb', line 22 def cycle(unit_delta) (unit_delta / duration.to_f).floor end |
#responsible(date = Date.today) ⇒ Object
13 14 15 |
# File 'lib/rotation/topic.rb', line 13 def responsible(date = Date.today) candidates[responsible_index(date)] end |
#responsible_index(date) ⇒ Object
17 18 19 20 |
# File 'lib/rotation/topic.rb', line 17 def responsible_index(date) unit_delta = week_delta(start_date, date) (cycle(unit_delta) + candidates.index(first)) % candidates.size end |
#week_delta(d1, d2) ⇒ Object
26 27 28 29 |
# File 'lib/rotation/topic.rb', line 26 def week_delta(d1, d2) year_difference = (d2.year - d1.year) * 52 year_difference + (d2 - d2.wday).yday / 7 - (d1 -d1.wday).yday / 7 end |