Class: CSstats::Players

Inherits:
Object
  • Object
show all
Defined in:
lib/csstats/players.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Players

Returns a new instance of Players.



5
6
7
# File 'lib/csstats/players.rb', line 5

def initialize(client)
  @client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

def save

CSstats::Parser.write_players(client, players)

end



37
38
39
40
# File 'lib/csstats/players.rb', line 37

def method_missing(method_name, *args, &block)
  return super unless respond_to?(method_name)
  players.send(method_name, *args, &block)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/csstats/players.rb', line 3

def client
  @client
end

Instance Method Details

#allObject



9
10
11
# File 'lib/csstats/players.rb', line 9

def all
  players
end

#find(id) ⇒ Object



13
14
15
# File 'lib/csstats/players.rb', line 13

def find(id)
  players[id - 1]
end

#find_by(attributes = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/csstats/players.rb', line 17

def find_by(attributes = {})
  players.find do |player|
    attributes.all? do |column, value|
      player.send(column) == value
    end
  end
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/csstats/players.rb', line 42

def respond_to_missing?(method_name, include_private = false)
  players.respond_to?(method_name, include_private)
end

#where(attributes = {}) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/csstats/players.rb', line 25

def where(attributes = {})
  players.select do |player|
    attributes.all? do |column, value|
      player.send(column) == value
    end
  end
end