Class: Opsgenie::Rotation
- Inherits:
-
Object
- Object
- Opsgenie::Rotation
- Defined in:
- lib/opsgenie/rotation.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#participants ⇒ Object
readonly
Returns the value of attribute participants.
-
#schedule ⇒ Object
readonly
Returns the value of attribute schedule.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
-
#time_restriction ⇒ Object
readonly
Returns the value of attribute time_restriction.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(schedule, attrs) ⇒ Rotation
constructor
A new instance of Rotation.
- #on_call_for_date(date) ⇒ Object
- #timeline(date: Date.today, interval: nil, interval_unit: nil) ⇒ Object
Constructor Details
#initialize(schedule, attrs) ⇒ Rotation
Returns a new instance of Rotation.
11 12 13 14 15 16 17 18 19 |
# File 'lib/opsgenie/rotation.rb', line 11 def initialize(schedule, attrs) @schedule = schedule @id = attrs["id"] @name = attrs["name"] @time_restriction = attrs["timeRestriction"] @start_date = DateTime.parse(attrs["startDate"]) @type = attrs["type"] @participants = attrs["participants"] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/opsgenie/rotation.rb', line 3 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/opsgenie/rotation.rb', line 3 def name @name end |
#participants ⇒ Object (readonly)
Returns the value of attribute participants.
3 4 5 |
# File 'lib/opsgenie/rotation.rb', line 3 def participants @participants end |
#schedule ⇒ Object (readonly)
Returns the value of attribute schedule.
3 4 5 |
# File 'lib/opsgenie/rotation.rb', line 3 def schedule @schedule end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
3 4 5 |
# File 'lib/opsgenie/rotation.rb', line 3 def start_date @start_date end |
#time_restriction ⇒ Object (readonly)
Returns the value of attribute time_restriction.
3 4 5 |
# File 'lib/opsgenie/rotation.rb', line 3 def time_restriction @time_restriction end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/opsgenie/rotation.rb', line 3 def type @type end |
Instance Method Details
#on_call_for_date(date) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/opsgenie/rotation.rb', line 21 def on_call_for_date(date) day_of_the_week = date.strftime("%A").downcase restriction = time_restriction["restrictions"].find { |r| r["startDay"] == day_of_the_week } return unless restriction time = Time.new( date.year, date.month, date.day, restriction["startHour"], restriction["startMin"] ) on_calls = schedule.on_calls((time + 60).to_datetime) on_calls.select { |user| participant_usernames.include?(user.username) } end |
#timeline(date: Date.today, interval: nil, interval_unit: nil) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/opsgenie/rotation.rb', line 41 def timeline(date: Date.today, interval: nil, interval_unit: nil) rotations = schedule.timeline( date: date, interval: interval, interval_unit: interval_unit ) rotations.find { |r| r.name == name } end |