Class: CoachClient::Sport
- Defined in:
- lib/coach_client/sport.rb
Overview
A sport resource of the CyberCoach service.
Instance Attribute Summary collapse
- #description ⇒ String readonly
- #id ⇒ Integer readonly
- #name ⇒ String readonly
- #sport ⇒ Symbol readonly
Attributes inherited from Resource
Class Method Summary collapse
-
.list(client) {|sport| ... } ⇒ Array<CoachClient::Sport>
Returns a list of sports from the CyberCoach service for which the given block returns a true value.
-
.path ⇒ String
Returns the relative path to the sport resource.
-
.total(client) ⇒ Integer
Returns the total number of sports present on the CyberCoach service.
Instance Method Summary collapse
-
#initialize(client, sport) ⇒ CoachClient::Sport
constructor
Creates a new sport.
-
#to_s ⇒ String
Returns the string representation of the sport.
-
#update ⇒ CoachClient::Sport
Updates the sport with the data from the CyberCoach service.
-
#url ⇒ String
Returns the URL of the sport.
Methods inherited from Resource
Constructor Details
#initialize(client, sport) ⇒ CoachClient::Sport
Creates a new sport.
54 55 56 57 |
# File 'lib/coach_client/sport.rb', line 54 def initialize(client, sport) super(client) @sport = sport.downcase.to_sym end |
Instance Attribute Details
#description ⇒ String (readonly)
11 12 13 |
# File 'lib/coach_client/sport.rb', line 11 def description @description end |
#id ⇒ Integer (readonly)
5 6 7 |
# File 'lib/coach_client/sport.rb', line 5 def id @id end |
#name ⇒ String (readonly)
11 12 13 |
# File 'lib/coach_client/sport.rb', line 11 def name @name end |
#sport ⇒ Symbol (readonly)
8 9 10 |
# File 'lib/coach_client/sport.rb', line 8 def sport @sport end |
Class Method Details
.list(client) {|sport| ... } ⇒ Array<CoachClient::Sport>
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.
39 40 41 42 43 44 45 46 47 |
# 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 |
.path ⇒ String
Returns the relative path to the sport resource.
16 17 18 |
# File 'lib/coach_client/sport.rb', line 16 def self.path 'sports/' end |
.total(client) ⇒ Integer
Returns the total number of sports present on the CyberCoach service.
24 25 26 27 28 |
# 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 |
Instance Method Details
#to_s ⇒ String
Returns the string representation of the sport.
82 83 84 |
# File 'lib/coach_client/sport.rb', line 82 def to_s @sport.to_s end |
#update ⇒ CoachClient::Sport
Updates the sport with the data from the CyberCoach service.
63 64 65 66 67 68 69 70 |
# 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 ⇒ String
Returns the URL of the sport.
75 76 77 |
# File 'lib/coach_client/sport.rb', line 75 def url @client.url + self.class.path + @sport.to_s end |