Class: FootballApi::Competition

Inherits:
BaseRequest show all
Includes:
Requestable
Defined in:
lib/football_api/competition.rb

Constant Summary

Constants inherited from BaseRequest

BaseRequest::RETRIES

Constants included from Symbolizer

Symbolizer::HASH_OR_ARRAY_KEYS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Requestable

included

Methods inherited from BaseRequest

action_query, get!, get_parameters, response

Methods included from Symbolizer

included

Constructor Details

#initialize(hash = {}) ⇒ Competition

Returns a new instance of Competition.



27
28
29
30
31
# File 'lib/football_api/competition.rb', line 27

def initialize(hash = {})
  @id     = hash[:id]
  @name   = hash[:name]
  @region = hash[:region]
end

Instance Attribute Details

#idObject

Response sample : [

{
  "id":"1064",
  "name":"Superliga",
  "region":"Albania"
} ...

]



15
16
17
# File 'lib/football_api/competition.rb', line 15

def id
  @id
end

#nameObject

Response sample : [

{
  "id":"1064",
  "name":"Superliga",
  "region":"Albania"
} ...

]



15
16
17
# File 'lib/football_api/competition.rb', line 15

def name
  @name
end

#regionObject

Response sample : [

{
  "id":"1064",
  "name":"Superliga",
  "region":"Albania"
} ...

]



15
16
17
# File 'lib/football_api/competition.rb', line 15

def region
  @region
end

Class Method Details

.allObject



17
18
19
20
21
# File 'lib/football_api/competition.rb', line 17

def self.all
  response && response.map do |comp|
    new(comp)
  end
end

.where(options = {}) ⇒ Object



23
24
25
# File 'lib/football_api/competition.rb', line 23

def self.where(options = {})
  response.select{ |c| matches_options(c, options) }.map{ |hsh| new(hsh) }
end