Class: RiotKit::Models::Riot::LazyMatchEntries
- Inherits:
-
Object
- Object
- RiotKit::Models::Riot::LazyMatchEntries
- Includes:
- Enumerable
- Defined in:
- lib/riot_kit/models/riot/lazy_match_entries.rb
Overview
Lazy Enumerable over match IDs: ‘get_match` runs only while you iterate, so `player.matches.first` triggers at most one match-detail request (plus the match-id list API).
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
- #first(count = nil) ⇒ Object
-
#initialize(match_history:) ⇒ LazyMatchEntries
constructor
A new instance of LazyMatchEntries.
Constructor Details
#initialize(match_history:) ⇒ LazyMatchEntries
Returns a new instance of LazyMatchEntries.
25 26 27 28 |
# File 'lib/riot_kit/models/riot/lazy_match_entries.rb', line 25 def initialize(match_history:) @match_history = match_history @detail_cache = {} end |
Class Method Details
.build(nickname:, filter:, puuid:, limit:, config:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/riot_kit/models/riot/lazy_match_entries.rb', line 13 def self.build(nickname:, filter:, puuid:, limit:, config:) history = Services::Riot::MatchHistory.new( nickname: nickname, filter: filter, puuid: puuid, limit: limit, config: config ) history.send(:prepare_ids_phase!) new(match_history: history) end |
Instance Method Details
#each ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/riot_kit/models/riot/lazy_match_entries.rb', line 30 def each return enum_for(__method__) unless block_given? id_list.each do |match_id| entry = fetch_or_cache_entry(match_id) yield entry if entry end end |
#first(count = nil) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/riot_kit/models/riot/lazy_match_entries.rb', line 39 def first(count = nil) return super unless count.nil? return @first_memo if defined?(@first_memo) @first_memo = super() end |