Class: Pinnacle::Optionals

Inherits:
Object
  • Object
show all
Defined in:
lib/rcs/types/optionals.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(additional_websites: OMIT, additional_phone_numbers: OMIT, additional_emails: OMIT, test_numbers: OMIT, additional_properties: nil) ⇒ Pinnacle::Optionals

Parameters:

  • additional_websites (Array<Pinnacle::AdditionalWebsite>) (defaults to: OMIT)

    List of additional websites, up to 2.

  • additional_phone_numbers (Array<Pinnacle::AdditionalPhoneNumber>) (defaults to: OMIT)

    List of additional phone numbers, up to 2.

  • additional_emails (Array<Pinnacle::AdditionalEmail>) (defaults to: OMIT)

    List of additional email addresses, up to 2.

  • test_numbers (Array<String>) (defaults to: OMIT)
  • 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
48
# File 'lib/rcs/types/optionals.rb', line 33

def initialize(additional_websites: OMIT, additional_phone_numbers: OMIT, additional_emails: OMIT,
               test_numbers: OMIT, additional_properties: nil)
  @additional_websites = additional_websites if additional_websites != OMIT
  @additional_phone_numbers = additional_phone_numbers if additional_phone_numbers != OMIT
  @additional_emails = additional_emails if additional_emails != OMIT
  @test_numbers = test_numbers if test_numbers != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "additionalWebsites": additional_websites,
    "additionalPhoneNumbers": additional_phone_numbers,
    "additionalEmails": additional_emails,
    "testNumbers": test_numbers
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_emailsArray<Pinnacle::AdditionalEmail> (readonly)

Returns List of additional email addresses, up to 2.

Returns:



16
17
18
# File 'lib/rcs/types/optionals.rb', line 16

def additional_emails
  @additional_emails
end

#additional_phone_numbersArray<Pinnacle::AdditionalPhoneNumber> (readonly)

Returns List of additional phone numbers, up to 2.

Returns:



14
15
16
# File 'lib/rcs/types/optionals.rb', line 14

def additional_phone_numbers
  @additional_phone_numbers
end

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



20
21
22
# File 'lib/rcs/types/optionals.rb', line 20

def additional_properties
  @additional_properties
end

#additional_websitesArray<Pinnacle::AdditionalWebsite> (readonly)

Returns List of additional websites, up to 2.

Returns:



12
13
14
# File 'lib/rcs/types/optionals.rb', line 12

def additional_websites
  @additional_websites
end

#test_numbersArray<String> (readonly)

Returns:

  • (Array<String>)


18
19
20
# File 'lib/rcs/types/optionals.rb', line 18

def test_numbers
  @test_numbers
end

Class Method Details

.from_json(json_object:) ⇒ Pinnacle::Optionals

Deserialize a JSON object to an instance of Optionals

Parameters:

  • json_object (String)

Returns:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rcs/types/optionals.rb', line 54

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  additional_websites = parsed_json["additionalWebsites"]&.map do |item|
    item = item.to_json
    Pinnacle::AdditionalWebsite.from_json(json_object: item)
  end
  additional_phone_numbers = parsed_json["additionalPhoneNumbers"]&.map do |item|
    item = item.to_json
    Pinnacle::AdditionalPhoneNumber.from_json(json_object: item)
  end
  additional_emails = parsed_json["additionalEmails"]&.map do |item|
    item = item.to_json
    Pinnacle::AdditionalEmail.from_json(json_object: item)
  end
  test_numbers = parsed_json["testNumbers"]
  new(
    additional_websites: additional_websites,
    additional_phone_numbers: additional_phone_numbers,
    additional_emails: additional_emails,
    test_numbers: test_numbers,
    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)


92
93
94
95
96
97
# File 'lib/rcs/types/optionals.rb', line 92

def self.validate_raw(obj:)
  obj.additional_websites&.is_a?(Array) != false || raise("Passed value for field obj.additional_websites is not the expected type, validation failed.")
  obj.additional_phone_numbers&.is_a?(Array) != false || raise("Passed value for field obj.additional_phone_numbers is not the expected type, validation failed.")
  obj.additional_emails&.is_a?(Array) != false || raise("Passed value for field obj.additional_emails is not the expected type, validation failed.")
  obj.test_numbers&.is_a?(Array) != false || raise("Passed value for field obj.test_numbers is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Optionals to a JSON object

Returns:

  • (String)


82
83
84
# File 'lib/rcs/types/optionals.rb', line 82

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