Class: TrophyApiClient::WrappedMetric
- Inherits:
-
Object
- Object
- TrophyApiClient::WrappedMetric
- Defined in:
- lib/trophy_api_client/types/wrapped_metric.rb
Overview
A user’s metric data for a wrapped period.
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#by_attribute ⇒ Hash{String => Hash}
readonly
Metric data broken down by attribute key and value.
-
#change_this_period ⇒ Float
readonly
The change in the metric value during the period.
-
#current_total ⇒ Float
readonly
The user’s current total for the metric.
-
#name ⇒ String
readonly
The name of the metric.
-
#percent_change ⇒ Float
readonly
The percentage change in the metric value during the period.
-
#percentile_this_period ⇒ Float
readonly
The user’s percentile rank for this metric during the period.
-
#units ⇒ String
readonly
The units of the metric.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ TrophyApiClient::WrappedMetric
Deserialize a JSON object to an instance of WrappedMetric.
-
.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.
Instance Method Summary collapse
- #initialize(name:, current_total:, change_this_period:, percent_change:, by_attribute:, units: OMIT, percentile_this_period: OMIT, additional_properties: nil) ⇒ TrophyApiClient::WrappedMetric constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of WrappedMetric to a JSON object.
Constructor Details
#initialize(name:, current_total:, change_this_period:, percent_change:, by_attribute:, units: OMIT, percentile_this_period: OMIT, additional_properties: nil) ⇒ TrophyApiClient::WrappedMetric
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 42 def initialize(name:, current_total:, change_this_period:, percent_change:, by_attribute:, units: OMIT, percentile_this_period: OMIT, additional_properties: nil) @name = name @units = units if units != 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 @by_attribute = by_attribute @additional_properties = additional_properties @_field_set = { "name": name, "units": units, "currentTotal": current_total, "changeThisPeriod": change_this_period, "percentChange": percent_change, "percentileThisPeriod": percentile_this_period, "byAttribute": by_attribute }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
25 26 27 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 25 def additional_properties @additional_properties end |
#by_attribute ⇒ Hash{String => Hash} (readonly)
Returns Metric data broken down by attribute key and value.
23 24 25 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 23 def by_attribute @by_attribute end |
#change_this_period ⇒ Float (readonly)
Returns The change in the metric value during the period.
16 17 18 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 16 def change_this_period @change_this_period end |
#current_total ⇒ Float (readonly)
Returns The user’s current total for the metric.
14 15 16 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 14 def current_total @current_total end |
#name ⇒ String (readonly)
Returns The name of the metric.
10 11 12 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 10 def name @name end |
#percent_change ⇒ Float (readonly)
Returns The percentage change in the metric value during the period.
18 19 20 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 18 def percent_change @percent_change end |
#percentile_this_period ⇒ Float (readonly)
Returns The user’s percentile rank for this metric during the period. Only included for weekly, monthly, and yearly aggregation periods.
21 22 23 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 21 def percentile_this_period @percentile_this_period end |
#units ⇒ String (readonly)
Returns The units of the metric.
12 13 14 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 12 def units @units end |
Class Method Details
.from_json(json_object:) ⇒ TrophyApiClient::WrappedMetric
Deserialize a JSON object to an instance of WrappedMetric
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 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 69 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) name = parsed_json["name"] units = parsed_json["units"] current_total = parsed_json["currentTotal"] change_this_period = parsed_json["changeThisPeriod"] percent_change = parsed_json["percentChange"] percentile_this_period = parsed_json["percentileThisPeriod"] by_attribute = parsed_json["byAttribute"]&.transform_values do |value| value&.transform_values do |value| value = value.to_json TrophyApiClient::WrappedMetricByAttributeValueValue.from_json(json_object: value) end end new( name: name, units: units, current_total: current_total, change_this_period: change_this_period, percent_change: percent_change, percentile_this_period: percentile_this_period, by_attribute: by_attribute, 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.
109 110 111 112 113 114 115 116 117 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 109 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.units&.is_a?(String) != false || raise("Passed value for field obj.units 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.") obj.by_attribute.is_a?(Hash) != false || raise("Passed value for field obj.by_attribute is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of WrappedMetric to a JSON object
99 100 101 |
# File 'lib/trophy_api_client/types/wrapped_metric.rb', line 99 def to_json(*_args) @_field_set&.to_json end |