Class: Hut::Room
- Inherits:
-
Object
- Object
- Hut::Room
- Defined in:
- lib/hut/room.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_message(msg) ⇒ Object
- #get_recent_messages ⇒ Object
-
#initialize(hut, room_name) ⇒ Room
constructor
A new instance of Room.
- #last_messages(num) ⇒ Object
- #listen ⇒ Object
- #new_message(body) ⇒ Object
- #window=(window) ⇒ Object
Constructor Details
#initialize(hut, room_name) ⇒ Room
Returns a new instance of Room.
6 7 8 9 10 11 12 13 14 |
# File 'lib/hut/room.rb', line 6 def initialize(hut, room_name) @hut = hut @name = room_name @room = @hut.campfire.rooms.select do |room| room.name.downcase == room_name end.first = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/hut/room.rb', line 4 def name @name end |
Instance Method Details
#add_message(msg) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/hut/room.rb', line 30 def (msg) if msg.body << @hut.(self, msg) @window.room_was_updated(self) if @window end end |
#get_recent_messages ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/hut/room.rb', line 41 def # Room#recent calls Time.parse require 'time' @room.recent.each do |msg| msg end end |
#last_messages(num) ⇒ Object
37 38 39 |
# File 'lib/hut/room.rb', line 37 def (num) .last(num) end |
#listen ⇒ Object
20 21 22 23 24 |
# File 'lib/hut/room.rb', line 20 def listen @room.listen do |msg| msg end end |
#new_message(body) ⇒ Object
26 27 28 |
# File 'lib/hut/room.rb', line 26 def (body) @room.speak body end |
#window=(window) ⇒ Object
16 17 18 |
# File 'lib/hut/room.rb', line 16 def window=(window) @window = window end |