Class: TrophyApiClient::CreateMetricRequestItem
- Inherits:
-
Object
- Object
- TrophyApiClient::CreateMetricRequestItem
- Defined in:
- lib/trophy_api_client/types/create_metric_request_item.rb
Overview
A metric to create.
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#key ⇒ String
readonly
The metric key.
-
#name ⇒ String
readonly
The metric name.
-
#unit_type ⇒ TrophyApiClient::CreateMetricRequestItemUnitType
readonly
The metric unit type.
-
#units ⇒ String
readonly
For ‘unitType: currency`, this must be a supported `MetricCurrency` code such as `USD`.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ TrophyApiClient::CreateMetricRequestItem
Deserialize a JSON object to an instance of CreateMetricRequestItem.
-
.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:, key:, unit_type: OMIT, units: OMIT, additional_properties: nil) ⇒ TrophyApiClient::CreateMetricRequestItem constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of CreateMetricRequestItem to a JSON object.
Constructor Details
#initialize(name:, key:, unit_type: OMIT, units: OMIT, additional_properties: nil) ⇒ TrophyApiClient::CreateMetricRequestItem
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 36 def initialize(name:, key:, unit_type: OMIT, units: OMIT, additional_properties: nil) @name = name @key = key @unit_type = unit_type if unit_type != OMIT @units = units if units != OMIT @additional_properties = additional_properties @_field_set = { "name": name, "key": key, "unitType": unit_type, "units": units }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
21 22 23 |
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 21 def additional_properties @additional_properties end |
#key ⇒ String (readonly)
Returns The metric key. Only alphanumeric characters, hyphens, and underscores are permitted.
14 15 16 |
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 14 def key @key end |
#name ⇒ String (readonly)
Returns The metric name.
11 12 13 |
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 11 def name @name end |
#unit_type ⇒ TrophyApiClient::CreateMetricRequestItemUnitType (readonly)
Returns The metric unit type. Defaults to ‘number`.
16 17 18 |
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 16 def unit_type @unit_type end |
#units ⇒ String (readonly)
Returns For ‘unitType: currency`, this must be a supported `MetricCurrency` code such as `USD`. For `number`, this is an optional freeform unit label.
19 20 21 |
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 19 def units @units end |
Class Method Details
.from_json(json_object:) ⇒ TrophyApiClient::CreateMetricRequestItem
Deserialize a JSON object to an instance of CreateMetricRequestItem
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 51 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) name = parsed_json["name"] key = parsed_json["key"] unit_type = parsed_json["unitType"] units = parsed_json["units"] new( name: name, key: key, unit_type: unit_type, units: units, 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.
80 81 82 83 84 85 |
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 80 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.key.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.") obj.unit_type&.is_a?(TrophyApiClient::CreateMetricRequestItemUnitType) != false || raise("Passed value for field obj.unit_type 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.") end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of CreateMetricRequestItem to a JSON object
70 71 72 |
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 70 def to_json(*_args) @_field_set&.to_json end |