Class: Dbl::BotSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/topgg/botSearch.rb

Overview

This class spreads the BotSearch Response body into different methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ BotSearch

Initalizes the BotSearch class

Parameters:

  • obj (Object)

    Response Hash



7
8
9
# File 'lib/topgg/botSearch.rb', line 7

def initialize(obj)
  @obj = obj
end

Instance Attribute Details

#objHash (readonly) Also known as: raw, data

Get raw hash response

Returns:

  • (Hash)


12
13
14
# File 'lib/topgg/botSearch.rb', line 12

def obj
  @obj
end

Instance Method Details

#countInteger

The number of bots shown in the first page

Returns:

  • (Integer)


32
33
34
# File 'lib/topgg/botSearch.rb', line 32

def count
  @obj['count'].to_i
end

#firstSpreader::Bot

The first result

Returns:

  • (Spreader::Bot)


26
27
28
# File 'lib/topgg/botSearch.rb', line 26

def first
  Spreader::Bot.new(@obj['results'][0])
end

#resultsArray<Spreader::Bot>

Iterates through the results

Returns:

  • (Array<Spreader::Bot>)


38
39
40
41
42
43
44
45
46
# File 'lib/topgg/botSearch.rb', line 38

def results
  arr = []
  flag = 0 # iteration flag
  @obj['results'].each do |data|
    arr[flag] = Spreader::Bot.new(data)
    flag += 1
  end
  arr
end

#sizeInteger

Length of the results.

Returns:

  • (Integer)


50
51
52
# File 'lib/topgg/botSearch.rb', line 50

def size
  @obj['results'].length
end

#totalInteger

The Total number of results

Returns:

  • (Integer)


20
21
22
# File 'lib/topgg/botSearch.rb', line 20

def total
  @obj['total'].to_i
end