Class: Intrinsic::EventTypeField

Inherits:
Object
  • Object
show all
Defined in:
lib/intrinsic/types/event_type_field.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_name:, type:, optional:, additional_properties: nil) ⇒ EventTypeField

Parameters:

  • field_name (String)

    Name of the field. Must be unique, and can only contain alphanumeric characters and underscores, and be up to 255 characters

  • type (EVENT_TYPE_FIELD_TYPE)

    Type of the field. Can be either strings, numbers, links to JPEG images, or links to video files

  • optional (Boolean)

    Whether the field is optional or not

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



15
16
17
18
19
20
21
22
23
24
# File 'lib/intrinsic/types/event_type_field.rb', line 15

def initialize(field_name:, type:, optional:, additional_properties: nil)
  # @type [String] Name of the field. Must be unique, and can only contain alphanumeric characters and underscores, and be up to 255 characters
  @field_name = field_name
  # @type [EVENT_TYPE_FIELD_TYPE] Type of the field. Can be either strings, numbers, links to JPEG images, or links to video files
  @type = type
  # @type [Boolean] Whether the field is optional or not
  @optional = optional
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



8
9
10
# File 'lib/intrinsic/types/event_type_field.rb', line 8

def additional_properties
  @additional_properties
end

#field_nameObject (readonly)

Returns the value of attribute field_name.



8
9
10
# File 'lib/intrinsic/types/event_type_field.rb', line 8

def field_name
  @field_name
end

#optionalObject (readonly)

Returns the value of attribute optional.



8
9
10
# File 'lib/intrinsic/types/event_type_field.rb', line 8

def optional
  @optional
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/intrinsic/types/event_type_field.rb', line 8

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ EventTypeField

Deserialize a JSON object to an instance of EventTypeField

Parameters:

  • json_object (JSON)

Returns:



30
31
32
33
34
35
36
37
# File 'lib/intrinsic/types/event_type_field.rb', line 30

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  field_name = struct.field_name
  type = EVENT_TYPE_FIELD_TYPE.key(parsed_json["type"]) || parsed_json["type"]
  optional = struct.optional
  new(field_name: field_name, type: type, optional: optional, 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)


50
51
52
53
54
# File 'lib/intrinsic/types/event_type_field.rb', line 50

def self.validate_raw(obj:)
  obj.field_name.is_a?(String) != false || raise("Passed value for field obj.field_name is not the expected type, validation failed.")
  obj.type.is_a?(EVENT_TYPE_FIELD_TYPE) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
  obj.optional.is_a?(Boolean) != false || raise("Passed value for field obj.optional is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of EventTypeField to a JSON object

Returns:

  • (JSON)


42
43
44
# File 'lib/intrinsic/types/event_type_field.rb', line 42

def to_json(*_args)
  { "field_name": @field_name, "type": EVENT_TYPE_FIELD_TYPE[@type] || @type, "optional": @optional }.to_json
end