class CoachClient::Sport

A sport resource of the CyberCoach service.

Attributes

description[R]

@return [String]

id[R]

@return [Integer]

name[R]

@return [String]

sport[R]

@return [Symbol]

Public Class Methods

list(client) { |sport| ... } click to toggle source

Returns a list of sports from the CyberCoach service for which the given block returns a true value.

If no block is given, the whole list is returned.

@param [CoachClient::Client] client @yieldparam [CoachClient::Sport] sport the sport @yieldreturn [Boolean] whether the sport should be added to the list @return [Array<CoachClient::Sport>] the list of sports

# File lib/coach_client/sport.rb, line 39
def self.list(client)
  sportlist  = []
  response = CoachClient::Request.get(client.url + path)
  response.to_h[:sports].each do |s|
    sport = new(client, s[:name])
    sportlist << sport if !block_given? || yield(sport)
  end
  sportlist
end
new(client, sport) click to toggle source

Creates a new sport.

@param [CoachClient::Client] client @param [String, Symbol] sport @return [CoachClient::Sport]

Calls superclass method CoachClient::Resource::new
# File lib/coach_client/sport.rb, line 54
def initialize(client, sport)
  super(client)
  @sport = sport.downcase.to_sym
end
path() click to toggle source

Returns the relative path to the sport resource.

@return [String] the relative path

# File lib/coach_client/sport.rb, line 16
def self.path
  'sports/'
end
total(client) click to toggle source

Returns the total number of sports present on the CyberCoach service.

@param [CoachClient::Client] client @return [Integer] the total number of sports

# File lib/coach_client/sport.rb, line 24
def self.total(client)
  response = CoachClient::Request.get(client.url + path,
                                      params: { size: 0 })
  response.to_h[:available]
end

Public Instance Methods

to_s() click to toggle source

Returns the string representation of the sport.

@return [String]

# File lib/coach_client/sport.rb, line 82
def to_s
  @sport.to_s
end
update() click to toggle source

Updates the sport with the data from the CyberCoach service.

@raise [CoachClient::NotFound] if the sport does not exist @return [CoachClient::Sport] the updated sport

# File lib/coach_client/sport.rb, line 63
def update
  response = CoachClient::Request.get(url)
  response = response.to_h
  @id = response[:id]
  @name = response[:name]
  @description = response[:description]
  self
end
url() click to toggle source

Returns the URL of the sport.

@return [String] the url of the sport

# File lib/coach_client/sport.rb, line 75
def url
  @client.url + self.class.path + @sport.to_s
end