Class: Pyre::Room
- Inherits:
-
Object
- Object
- Pyre::Room
- Defined in:
- lib/pyre/room.rb
Overview
Pyre::Room is for interacting with a room!
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, url, id, campfire) ⇒ Room
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#join ⇒ Object
Enter the room.
-
#joined? ⇒ Boolean
If you’re in the room right now.
-
#leave ⇒ Object
Leave the room.
-
#paste(message) ⇒ Object
Paste
message
to the room. -
#speak(message) ⇒ Object
Send
message
to the room.
Constructor Details
#initialize(name, url, id, campfire) ⇒ Room
:nodoc:
6 7 8 9 10 11 |
# File 'lib/pyre/room.rb', line 6 def initialize(name, url, id, campfire) #:nodoc: @name = name @url = url @id = id @campfire = campfire end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/pyre/room.rb', line 4 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/pyre/room.rb', line 4 def name @name end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
49 50 51 |
# File 'lib/pyre/room.rb', line 49 def inspect #:nodoc: "#<#{self.class} \"#{@name}\" \"#{@url}\">" end |
#join ⇒ Object
Enter the room. Returns true on success.
14 15 16 17 |
# File 'lib/pyre/room.rb', line 14 def join @campfire.agent.get(@url) joined? end |
#joined? ⇒ Boolean
If you’re in the room right now.
29 30 31 |
# File 'lib/pyre/room.rb', line 29 def joined? @campfire.agent.current_page.at('h1[@id="room_name"]').inner_text == @name rescue false end |
#leave ⇒ Object
Leave the room. Returns true on success.
20 21 22 23 24 25 26 |
# File 'lib/pyre/room.rb', line 20 def leave if joined? leave = @campfire.agent.current_page.links.detect {|link| link.text == 'Leave'} @campfire.agent.post(leave.uri) not joined? end end |
#paste(message) ⇒ Object
Paste message
to the room. Joins the room if necessary.
42 43 44 45 46 47 |
# File 'lib/pyre/room.rb', line 42 def paste() result = submit_chat_form(, 'paste' => 'true') success = (result.links.detect {|link| link.text == 'View paste'} and result.uri.to_s == "#{@url}/speak") join success end |
#speak(message) ⇒ Object
Send message
to the room. Joins the room if necessary.
34 35 36 37 38 39 |
# File 'lib/pyre/room.rb', line 34 def speak() result = submit_chat_form() success = (result.uri.to_s == "#{@url}/speak") join success end |