Class: SteamMist::PseudoInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/steam_mist/pseudo_interface.rb,
lib/steam_mist/pseudo_interface/pseudo_method.rb

Overview

This basically represents an interface for the Web API.

Defined Under Namespace

Classes: PseudoMethod

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, interface_name) ⇒ PseudoInterface

Initialize the pseudointerface with the interface name. See #api_name for information about how this is handled.

Parameters:

  • session (Session)

    the session the interface is a part of.

  • interface_name (Symbol)

    the interface name.



24
25
26
27
# File 'lib/steam_mist/pseudo_interface.rb', line 24

def initialize(session, interface_name)
  @name     = interface_name
  @session  = session
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Some #method_missing magic. Sorry @charliesome!

See Also:

  • SteamMist::PseudoInterface.{{#get_method}


62
63
64
65
# File 'lib/steam_mist/pseudo_interface.rb', line 62

def method_missing(method, *args)
  super if args.length > 1 or block_given?
  get_method method, *args
end

Instance Attribute Details

#nameSymbol (readonly)

The interface’s name that this is representing. This should be in underscore form.

Returns:

  • (Symbol)

    the name of the interface.



11
12
13
# File 'lib/steam_mist/pseudo_interface.rb', line 11

def name
  @name
end

#sessionSession (readonly)

The session that the interface is running under. This is used mainly for the connector.

Returns:



17
18
19
# File 'lib/steam_mist/pseudo_interface.rb', line 17

def session
  @session
end

Instance Method Details

#api_nameString

Turns the interface name into the corresponding api name. If the interface starts with an ‘I`, it makes no modifications to it (other than turning it into a string). If it doesn’t, however, it turns it from snake case to camel case (i.e. ‘some_interface` to `SomeInterface`). It then adds an `I` to the front of it.

Returns:

  • (String)

    the API name used by the Steam Web API.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/steam_mist/pseudo_interface.rb', line 45

def api_name
  @_api_name ||= begin
    str = name.to_s

    if str[0] == "I"
      str
    else
      str.gsub!(/_([a-z])/) { |m| m[1].upcase }
      str[0] = str[0].upcase
      "I#{str}"
    end
  end
end

#get_method(method_name, version = 1) ⇒ PseudoMethod

Grab a method from this interface.

Parameters:

  • method_name (Symbol)

    the name of the method.

  • version (Numeric) (defaults to: 1)

    the version of the method.

Returns:



34
35
36
# File 'lib/steam_mist/pseudo_interface.rb', line 34

def get_method(method_name, version=1)
  PseudoMethod.new(self, method_name, version)
end

#inspectString

Pretty inspection.

Returns:

  • (String)


70
71
72
# File 'lib/steam_mist/pseudo_interface.rb', line 70

def inspect
  "#<SteamMist::PseudoInterface #{name}>"
end