Class: FoldingAtHomeClient::Team
- Inherits:
-
Object
- Object
- FoldingAtHomeClient::Team
- Extended by:
- Request
- Includes:
- Request
- Defined in:
- lib/folding_at_home_client/team.rb
Constant Summary
Constants included from Request
Request::API_URL, Request::HEADERS
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#founder ⇒ Object
readonly
Returns the value of attribute founder.
-
#id ⇒ Object
Returns the value of attribute id.
-
#logo ⇒ Object
readonly
Returns the value of attribute logo.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user_score ⇒ Object
readonly
Returns the value of attribute user_score.
-
#user_wus ⇒ Object
readonly
Returns the value of attribute user_wus.
-
#wus ⇒ Object
readonly
Returns the value of attribute wus.
Class Method Summary collapse
- .escape_param(name) ⇒ Object
-
.find_by(id: nil, name: nil) ⇒ Object
rubocop:enable Lint/UnusedMethodArgument.
Instance Method Summary collapse
-
#initialize(id: nil, team: nil, name: nil, wus: nil, rank: nil, trank: nil, credit: nil, tscore: nil, twus: nil, founder: nil, score: nil, url: nil, logo: nil, last: nil, active_7: nil, active_50: nil, error: nil) ⇒ Team
constructor
rubocop:disable Lint/UnusedMethodArgument.
- #members ⇒ Object
Methods included from Request
connection, format_response, request, request_and_instantiate_objects, request_unencoded
Constructor Details
#initialize(id: nil, team: nil, name: nil, wus: nil, rank: nil, trank: nil, credit: nil, tscore: nil, twus: nil, founder: nil, score: nil, url: nil, logo: nil, last: nil, active_7: nil, active_50: nil, error: nil) ⇒ Team
rubocop:disable Lint/UnusedMethodArgument
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/folding_at_home_client/team.rb', line 20 def initialize( id: nil, team: nil, name: nil, wus: nil, rank: nil, trank: nil, credit: nil, tscore: nil, twus: nil, founder: nil, score: nil, url: nil, logo: nil, last: nil, active_7: nil, active_50: nil, error: nil ) @id = id || team.to_i if id || team @name = name if name @rank = trank || rank if trank || rank @score = tscore || credit if tscore || credit @wus = twus || wus if twus || wus @founder = founder if founder @url = url if url @logo = logo if logo @user_score = score if !tscore.nil? && score @user_wus = wus if !twus.nil? && wus @error = error if error end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
9 10 11 |
# File 'lib/folding_at_home_client/team.rb', line 9 def error @error end |
#founder ⇒ Object (readonly)
Returns the value of attribute founder.
9 10 11 |
# File 'lib/folding_at_home_client/team.rb', line 9 def founder @founder end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/folding_at_home_client/team.rb', line 8 def id @id end |
#logo ⇒ Object (readonly)
Returns the value of attribute logo.
9 10 11 |
# File 'lib/folding_at_home_client/team.rb', line 9 def logo @logo end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/folding_at_home_client/team.rb', line 8 def name @name end |
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
9 10 11 |
# File 'lib/folding_at_home_client/team.rb', line 9 def rank @rank end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
9 10 11 |
# File 'lib/folding_at_home_client/team.rb', line 9 def score @score end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/folding_at_home_client/team.rb', line 9 def url @url end |
#user_score ⇒ Object (readonly)
Returns the value of attribute user_score.
9 10 11 |
# File 'lib/folding_at_home_client/team.rb', line 9 def user_score @user_score end |
#user_wus ⇒ Object (readonly)
Returns the value of attribute user_wus.
9 10 11 |
# File 'lib/folding_at_home_client/team.rb', line 9 def user_wus @user_wus end |
#wus ⇒ Object (readonly)
Returns the value of attribute wus.
9 10 11 |
# File 'lib/folding_at_home_client/team.rb', line 9 def wus @wus end |
Class Method Details
.escape_param(name) ⇒ Object
112 113 114 |
# File 'lib/folding_at_home_client/team.rb', line 112 def self.escape_param(name) name.gsub(' ', '%20').gsub('&', '%26').gsub(',', '%2C') end |
.find_by(id: nil, name: nil) ⇒ Object
rubocop:enable Lint/UnusedMethodArgument
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/folding_at_home_client/team.rb', line 58 def self.find_by(id: nil, name: nil) team = allocate team.id ||= id if id team.name ||= name if name endpoint_and_params = '/team' if team.id && !team.id.to_s.empty? endpoint_and_params += "/#{team.id}" elsif team.name && !team.name.empty? endpoint_and_params += "/find?name=#{escape_param(team.name)}" else raise ArgumentError, 'Required: id or name of team' end team_hash = nil begin team_hash = request_unencoded(endpoint_and_params:).first raise StandardError if team_hash[:error] rescue StandardError if team.name query_endpoint_and_params = "/team?q=#{escape_param(team.name)}" query_team_hash = request_unencoded(endpoint_and_params: query_endpoint_and_params).first team.id = query_team_hash&.fetch(:id, nil) endpoint = "/#{team.id}" team_hash = request(endpoint:).first if team.id end end error = team_hash[:error] team_hash.delete(:status) if error team.send(:initialize, **team_hash) team end |
Instance Method Details
#members ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/folding_at_home_client/team.rb', line 99 def members endpoint = "/team/#{@id}/members" members_array = request(endpoint:) keys = members_array.shift.map(&:to_sym) members_array.map do |member_array| member_hash = Hash[keys.zip(member_array)] User.new(**member_hash) end end |