Class: TrophyApiClient::StreakResponseStreakHistoryItem

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

Overview

An object representing a past streak period.

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(period_start:, period_end:, length:, used_freeze: OMIT, additional_properties: nil) ⇒ TrophyApiClient::StreakResponseStreakHistoryItem

Parameters:

  • period_start (String)

    The date this streak period started.

  • period_end (String)

    The date this streak period ended.

  • length (Integer)

    The length of the user’s streak during this period.

  • used_freeze (Boolean) (defaults to: OMIT)

    Whether the user used a streak freeze during this period. Only present if the organization has enabled streak freezes.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/trophy_api_client/types/streak_response_streak_history_item.rb', line 33

def initialize(period_start:, period_end:, length:, used_freeze: OMIT, additional_properties: nil)
  @period_start = period_start
  @period_end = period_end
  @length = length
  @used_freeze = used_freeze if used_freeze != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "periodStart": period_start,
    "periodEnd": period_end,
    "length": length,
    "usedFreeze": used_freeze
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



19
20
21
# File 'lib/trophy_api_client/types/streak_response_streak_history_item.rb', line 19

def additional_properties
  @additional_properties
end

#lengthInteger (readonly)

Returns The length of the user’s streak during this period.

Returns:

  • (Integer)

    The length of the user’s streak during this period.



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

def length
  @length
end

#period_endString (readonly)

Returns The date this streak period ended.

Returns:

  • (String)

    The date this streak period ended.



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

def period_end
  @period_end
end

#period_startString (readonly)

Returns The date this streak period started.

Returns:

  • (String)

    The date this streak period started.



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

def period_start
  @period_start
end

#used_freezeBoolean (readonly)

Returns Whether the user used a streak freeze during this period. Only present if the organization has enabled streak freezes.

Returns:

  • (Boolean)

    Whether the user used a streak freeze during this period. Only present if the organization has enabled streak freezes.



17
18
19
# File 'lib/trophy_api_client/types/streak_response_streak_history_item.rb', line 17

def used_freeze
  @used_freeze
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::StreakResponseStreakHistoryItem

Deserialize a JSON object to an instance of StreakResponseStreakHistoryItem

Parameters:

  • json_object (String)

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/trophy_api_client/types/streak_response_streak_history_item.rb', line 53

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  period_start = parsed_json["periodStart"]
  period_end = parsed_json["periodEnd"]
  length = parsed_json["length"]
  used_freeze = parsed_json["usedFreeze"]
  new(
    period_start: period_start,
    period_end: period_end,
    length: length,
    used_freeze: used_freeze,
    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:

  • obj (Object)

Returns:

  • (Void)


82
83
84
85
86
87
# File 'lib/trophy_api_client/types/streak_response_streak_history_item.rb', line 82

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

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of StreakResponseStreakHistoryItem to a JSON object

Returns:

  • (String)


72
73
74
# File 'lib/trophy_api_client/types/streak_response_streak_history_item.rb', line 72

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