Class: Spectate::Status

Inherits:
Object
  • Object
show all
Includes:
Encode
Defined in:
lib/spectate/status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Encode

#decode, #encode

Constructor Details

#initialize(server, source, properties = {}) ⇒ Status

Returns a new instance of Status.



5
6
7
8
9
10
11
# File 'lib/spectate/status.rb', line 5

def initialize(server, source, properties = {})
  @server, @source = server, source
  @status = properties.inject({}) do |status, (key, value)|  # Shamelessly lifted from ActiveSupport
    status[(key.to_sym rescue key) || key] = value
    status
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/spectate/status.rb', line 35

def method_missing(method, *args, &block)
  if @status.has_key?(method)
    @status[method]
  else
    super
  end
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



4
5
6
# File 'lib/spectate/status.rb', line 4

def server
  @server
end

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/spectate/status.rb', line 4

def source
  @source
end

Instance Method Details

#[](key) ⇒ Object



31
32
33
# File 'lib/spectate/status.rb', line 31

def [](key)
  @status[key]
end

#nameObject

The English representation of the name of the spectator belonging to this source.



27
28
29
# File 'lib/spectate/status.rb', line 27

def name
  decode @source.slice(%r{/[^/]+$}).delete('/')  # Ruby 1.8 doesn't support lookbehind
end

#parentObject

Returns the path of the spectator that owns this source. In practical terms, this simply truncates to the next-to-last element on the path; so if the source is ‘/examples/foo/re_bar’ the parent would be ‘/examples/foo’.



22
23
24
# File 'lib/spectate/status.rb', line 22

def parent
  @source.slice %r{^/.*(?=/)}
end

#propertiesObject

An array of all the properties contained in this Status object.



14
15
16
# File 'lib/spectate/status.rb', line 14

def properties
  @status.keys
end