Class: Pyre::Room

Inherits:
Object
  • Object
show all
Defined in:
lib/pyre/room.rb

Overview

Pyre::Room is for interacting with a room!

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/pyre/room.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/pyre/room.rb', line 4

def name
  @name
end

Instance Method Details

#inspectObject

:nodoc:



49
50
51
# File 'lib/pyre/room.rb', line 49

def inspect #:nodoc:
  "#<#{self.class} \"#{@name}\" \"#{@url}\">"
end

#joinObject

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.

Returns:

  • (Boolean)


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

#leaveObject

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(message)
  result = submit_chat_form(message, '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(message)
  result = submit_chat_form(message)
  success = (result.uri.to_s == "#{@url}/speak")
  join
  success
end