Class: Lita::WeeklySchedule

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/weekly_schedule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, room_id:, user_id:, day:, time:, cmd:) ⇒ WeeklySchedule

Returns a new instance of WeeklySchedule.



5
6
7
8
9
10
# File 'lib/lita/weekly_schedule.rb', line 5

def initialize(id:, room_id:, user_id:, day:, time:, cmd:)
  @id = id
  @room_id, @user_id = room_id, user_id
  @day, @time = day.to_s.to_sym, time.to_s
  @cmd = cmd.new if cmd
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



3
4
5
# File 'lib/lita/weekly_schedule.rb', line 3

def cmd
  @cmd
end

#dayObject (readonly)

Returns the value of attribute day.



3
4
5
# File 'lib/lita/weekly_schedule.rb', line 3

def day
  @day
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/lita/weekly_schedule.rb', line 3

def id
  @id
end

#room_idObject (readonly)

Returns the value of attribute room_id.



3
4
5
# File 'lib/lita/weekly_schedule.rb', line 3

def room_id
  @room_id
end

#timeObject (readonly)

Returns the value of attribute time.



3
4
5
# File 'lib/lita/weekly_schedule.rb', line 3

def time
  @time
end

#user_idObject (readonly)

Returns the value of attribute user_id.



3
4
5
# File 'lib/lita/weekly_schedule.rb', line 3

def user_id
  @user_id
end

Instance Method Details

#humanObject



35
36
37
# File 'lib/lita/weekly_schedule.rb', line 35

def human
  "Weekly (id: #{@id}): #{@day} #{@time} - #{@cmd.name}"
end

#nameObject



12
13
14
# File 'lib/lita/weekly_schedule.rb', line 12

def name
  @cmd.name
end

#run(*args) ⇒ Object



16
17
18
# File 'lib/lita/weekly_schedule.rb', line 16

def run(*args)
  @cmd.run(*args)
end

#to_jsonObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/lita/weekly_schedule.rb', line 24

def to_json
  {
    id: @id,
    day: @day,
    time: @time,
    cmd: @cmd.name,
    user_id: @user_id,
    room_id: @room_id,
  }.to_json
end

#valid?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/lita/weekly_schedule.rb', line 20

def valid?
  room_id && user_id && valid_day? && valid_time? && valid_cmd?
end