Class: DotaApiWrapper::Match

Inherits:
Base
  • Object
show all
Defined in:
lib/dota_api_wrapper/match.rb

Constant Summary

Constants inherited from Base

Base::API_KEY, Base::BASE_URI

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#get, retrieve_info

Constructor Details

#initialize(match_info) ⇒ Match

Returns a new instance of Match.



10
11
12
13
# File 'lib/dota_api_wrapper/match.rb', line 10

def initialize(match_info)
  match_info.delete('players')
  @match_info = match_info
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

If the parameter name exists in the hash, it will be returned In other case in will raise an exception ‘NoMethodError’



17
18
19
20
21
22
23
24
25
# File 'lib/dota_api_wrapper/match.rb', line 17

def method_missing(name, *args, &block)
  if match_info.key?(name.to_s)
    match_info[name.to_s]
  elsif match_details.key?(name.to_s)
    match_details[name.to_s]
  else
    super
  end
end

Instance Attribute Details

#match_detailsObject

Returns the value of attribute match_details.



8
9
10
# File 'lib/dota_api_wrapper/match.rb', line 8

def match_details
  @match_details
end

#match_infoObject

Returns the value of attribute match_info.



7
8
9
# File 'lib/dota_api_wrapper/match.rb', line 7

def match_info
  @match_info
end

Class Method Details

.get_matches(options = {}) ⇒ Object

Consume API wrapper to get matches



37
38
39
40
# File 'lib/dota_api_wrapper/match.rb', line 37

def self.get_matches(options = {})
  api_result = retrieve_info('/GetMatchHistory/V001', options)
  return api_result['result'] unless api_result.empty?
end

Instance Method Details

#complete_detailsObject

Return hash with all data from match



32
33
34
# File 'lib/dota_api_wrapper/match.rb', line 32

def complete_details
  match_info.merge(match_details)
end