Class: LoLBase::Summoner
- Inherits:
-
Object
- Object
- LoLBase::Summoner
- Defined in:
- lib/lolbase/data/summoner.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_modified ⇒ Object
readonly
Returns the value of attribute last_modified.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Instance Method Summary collapse
-
#initialize(params, connection) ⇒ Summoner
constructor
Input - params - A hash containing either a summoner name or ID, the region that they belong to, and whether to preload the object with Riot’s data (e.g. { id: 123, region: “na”, preload: false }) - connection - Current connection to the Riot API.
- #load ⇒ Object
- #profile_icon ⇒ Object
-
#stats(type = nil) ⇒ Object
Return stats for the given summoner.
Constructor Details
#initialize(params, connection) ⇒ Summoner
Input
-
params - A hash containing either a summoner name or ID, the region that they belong to, and whether to preload the object with Riot’s data (e.g. { id: 123, region: “na”, preload: false })
-
connection - Current connection to the Riot API
Output: Returns a Summoner object for further chaining
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lolbase/data/summoner.rb', line 13 def initialize(params, connection) @id = params[:id] @name = params[:name] @region = params[:region] @connection = connection load unless params[:preload] == false self end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/lolbase/data/summoner.rb', line 5 def id @id end |
#last_modified ⇒ Object (readonly)
Returns the value of attribute last_modified.
5 6 7 |
# File 'lib/lolbase/data/summoner.rb', line 5 def last_modified @last_modified end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
5 6 7 |
# File 'lib/lolbase/data/summoner.rb', line 5 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/lolbase/data/summoner.rb', line 5 def name @name end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
5 6 7 |
# File 'lib/lolbase/data/summoner.rb', line 5 def region @region end |
Instance Method Details
#load ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lolbase/data/summoner.rb', line 24 def load response = if !@id.nil? # Find summoner by ID @connection.get "/api/lol/#{@region}/v#{LoLBase.config.version_summoner}/summoner/#{@id}" else # Find summoner by name @connection.get "/api/lol/#{@region}/v#{LoLBase.config.version_summoner}/summoner/by-name/#{@name}" end # Populate object with response data data = JSON.parse(response) @id = data["id"] @name = data["name"] @profile_icon = ProfileIcon.new data["profileIconId"], self @last_modified = Time.at(data["revisionDate"] / 1000) @level = data["summonerLevel"] end |
#profile_icon ⇒ Object
43 44 45 |
# File 'lib/lolbase/data/summoner.rb', line 43 def profile_icon return @profile_icon || ProfileIcon.new(nil, self) end |
#stats(type = nil) ⇒ Object
Return stats for the given summoner. Syntactic sugar for retrieving summary or ranked stats.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lolbase/data/summoner.rb', line 49 def stats(type = nil) @stats ||= Stats.new(self, @connection) if type == :summary return @stats.summary elsif type == :ranked return @stats.ranked else return @stats end end |