Class: TrophyApiClient::LeaderboardRanking

Inherits:
Object
  • Object
show all
Defined in:
lib/trophy_api_client/types/leaderboard_ranking.rb

Overview

A user’s ranking in a leaderboard.

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id:, rank:, value:, user_name: OMIT, additional_properties: nil) ⇒ TrophyApiClient::LeaderboardRanking



31
32
33
34
35
36
37
38
39
40
# File 'lib/trophy_api_client/types/leaderboard_ranking.rb', line 31

def initialize(user_id:, rank:, value:, user_name: OMIT, additional_properties: nil)
  @user_id = user_id
  @user_name = user_name if user_name != OMIT
  @rank = rank
  @value = value
  @additional_properties = additional_properties
  @_field_set = { "userId": user_id, "userName": user_name, "rank": rank, "value": value }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)



18
19
20
# File 'lib/trophy_api_client/types/leaderboard_ranking.rb', line 18

def additional_properties
  @additional_properties
end

#rankInteger (readonly)



14
15
16
# File 'lib/trophy_api_client/types/leaderboard_ranking.rb', line 14

def rank
  @rank
end

#user_idString (readonly)



10
11
12
# File 'lib/trophy_api_client/types/leaderboard_ranking.rb', line 10

def user_id
  @user_id
end

#user_nameString (readonly)



12
13
14
# File 'lib/trophy_api_client/types/leaderboard_ranking.rb', line 12

def user_name
  @user_name
end

#valueInteger (readonly)



16
17
18
# File 'lib/trophy_api_client/types/leaderboard_ranking.rb', line 16

def value
  @value
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::LeaderboardRanking

Deserialize a JSON object to an instance of LeaderboardRanking



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/trophy_api_client/types/leaderboard_ranking.rb', line 46

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  user_id = parsed_json["userId"]
  user_name = parsed_json["userName"]
  rank = parsed_json["rank"]
  value = parsed_json["value"]
  new(
    user_id: user_id,
    user_name: user_name,
    rank: rank,
    value: value,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.


75
76
77
78
79
80
# File 'lib/trophy_api_client/types/leaderboard_ranking.rb', line 75

def self.validate_raw(obj:)
  obj.user_id.is_a?(String) != false || raise("Passed value for field obj.user_id is not the expected type, validation failed.")
  obj.user_name&.is_a?(String) != false || raise("Passed value for field obj.user_name is not the expected type, validation failed.")
  obj.rank.is_a?(Integer) != false || raise("Passed value for field obj.rank is not the expected type, validation failed.")
  obj.value.is_a?(Integer) != false || raise("Passed value for field obj.value is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of LeaderboardRanking to a JSON object



65
66
67
# File 'lib/trophy_api_client/types/leaderboard_ranking.rb', line 65

def to_json(*_args)
  @_field_set&.to_json
end