Class: RLS::SearchResults

Inherits:
Object
  • Object
show all
Defined in:
lib/rls/objects/search_results.rb

Overview

Search results from RLS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data, display_name) ⇒ SearchResults

Returns a new instance of SearchResults



24
25
26
27
28
29
30
31
32
# File 'lib/rls/objects/search_results.rb', line 24

def initialize(client, data, display_name)
  @client               = client
  @display_name         = display_name
  @page                 = data['page']
  @results              = data['results']
  @total_results        = data['totalResults']
  @max_results_per_page = data['maxResultsPerPage']
  @players              = data['data'].map { |e| Player.new(e) }
end

Instance Attribute Details

#display_nameString (readonly)

Returns the search query

Returns:

  • (String)

    the search query



7
8
9
# File 'lib/rls/objects/search_results.rb', line 7

def display_name
  @display_name
end

#max_results_per_pageInteger (readonly)

Returns:

  • (Integer)


19
20
21
# File 'lib/rls/objects/search_results.rb', line 19

def max_results_per_page
  @max_results_per_page
end

#pageInteger (readonly)

Returns current page

Returns:

  • (Integer)

    current page



10
11
12
# File 'lib/rls/objects/search_results.rb', line 10

def page
  @page
end

#playersArray<Player> (readonly)

Returns array of Player objects that have been fetched so far

Returns:

  • (Array<Player>)

    array of Player objects that have been fetched so far



22
23
24
# File 'lib/rls/objects/search_results.rb', line 22

def players
  @players
end

#resultsInteger (readonly)

Returns amount of results in this query

Returns:

  • (Integer)

    amount of results in this query



13
14
15
# File 'lib/rls/objects/search_results.rb', line 13

def results
  @results
end

#total_resultsInteger (readonly)

Returns total amount of players returned by the query

Returns:

  • (Integer)

    total amount of players returned by the query



16
17
18
# File 'lib/rls/objects/search_results.rb', line 16

def total_results
  @total_results
end

Instance Method Details

#allArray<Player>

Continuously requests all available pages that the query can produce, and returns all of the player objects

Returns:

  • (Array<Player>)

    All the players from the query



46
47
48
49
50
# File 'lib/rls/objects/search_results.rb', line 46

def all
  until next_page.empty?
  end
  players
end

#next_pageArray<Player>

Returns Retrieves the next page of Player objects

Returns:

  • (Array<Player>)

    Retrieves the next page of Player objects



35
36
37
38
39
40
41
42
# File 'lib/rls/objects/search_results.rb', line 35

def next_page
  return [] if results < max_results_per_page
  @page += 1
  search = @client.search(display_name, page)
  @results = search.results
  @players += search.players
  search.players
end