Class: TrophyApiClient::WrappedPoints

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

Overview

A user’s points data for a wrapped period.

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, current_total:, change_this_period:, percent_change:, description: OMIT, percentile_this_period: OMIT, additional_properties: nil) ⇒ TrophyApiClient::WrappedPoints

Parameters:

  • The name of the points system.

  • (defaults to: OMIT)

    The description of the points system.

  • The user’s current total points.

  • The change in points during the period.

  • The percentage change in points during the period.

  • (defaults to: OMIT)

    The user’s percentile rank for this points system during the period. Only included for weekly, monthly, and yearly aggregation periods.

  • (defaults to: nil)

    Additional properties unmapped to the current class definition



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/trophy_api_client/types/wrapped_points.rb', line 39

def initialize(name:, current_total:, change_this_period:, percent_change:, description: OMIT,
               percentile_this_period: OMIT, additional_properties: nil)
  @name = name
  @description = description if description != OMIT
  @current_total = current_total
  @change_this_period = change_this_period
  @percent_change = percent_change
  @percentile_this_period = percentile_this_period if percentile_this_period != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "name": name,
    "description": description,
    "currentTotal": current_total,
    "changeThisPeriod": change_this_period,
    "percentChange": percent_change,
    "percentileThisPeriod": percentile_this_period
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • Additional properties unmapped to the current class definition



23
24
25
# File 'lib/trophy_api_client/types/wrapped_points.rb', line 23

def additional_properties
  @additional_properties
end

#change_this_periodFloat (readonly)

Returns The change in points during the period.

Returns:

  • The change in points during the period.



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

def change_this_period
  @change_this_period
end

#current_totalFloat (readonly)

Returns The user’s current total points.

Returns:

  • The user’s current total points.



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

def current_total
  @current_total
end

#descriptionString (readonly)

Returns The description of the points system.

Returns:

  • The description of the points system.



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

def description
  @description
end

#nameString (readonly)

Returns The name of the points system.

Returns:

  • The name of the points system.



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

def name
  @name
end

#percent_changeFloat (readonly)

Returns The percentage change in points during the period.

Returns:

  • The percentage change in points during the period.



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

def percent_change
  @percent_change
end

#percentile_this_periodFloat (readonly)

Returns The user’s percentile rank for this points system during the period. Only included for weekly, monthly, and yearly aggregation periods.

Returns:

  • The user’s percentile rank for this points system during the period. Only included for weekly, monthly, and yearly aggregation periods.



21
22
23
# File 'lib/trophy_api_client/types/wrapped_points.rb', line 21

def percentile_this_period
  @percentile_this_period
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::WrappedPoints

Deserialize a JSON object to an instance of WrappedPoints

Parameters:

Returns:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/trophy_api_client/types/wrapped_points.rb', line 64

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  name = parsed_json["name"]
  description = parsed_json["description"]
  current_total = parsed_json["currentTotal"]
  change_this_period = parsed_json["changeThisPeriod"]
  percent_change = parsed_json["percentChange"]
  percentile_this_period = parsed_json["percentileThisPeriod"]
  new(
    name: name,
    description: description,
    current_total: current_total,
    change_this_period: change_this_period,
    percent_change: percent_change,
    percentile_this_period: percentile_this_period,
    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.

Parameters:

Returns:



97
98
99
100
101
102
103
104
# File 'lib/trophy_api_client/types/wrapped_points.rb', line 97

def self.validate_raw(obj:)
  obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  obj.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.")
  obj.current_total.is_a?(Float) != false || raise("Passed value for field obj.current_total is not the expected type, validation failed.")
  obj.change_this_period.is_a?(Float) != false || raise("Passed value for field obj.change_this_period is not the expected type, validation failed.")
  obj.percent_change.is_a?(Float) != false || raise("Passed value for field obj.percent_change is not the expected type, validation failed.")
  obj.percentile_this_period&.is_a?(Float) != false || raise("Passed value for field obj.percentile_this_period is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of WrappedPoints to a JSON object

Returns:



87
88
89
# File 'lib/trophy_api_client/types/wrapped_points.rb', line 87

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