Class: AssemblyAI::Transcripts::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/assemblyai/transcripts/types/entity.rb

Overview

A detected entity

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity_type:, text:, start:, end_:, additional_properties: nil) ⇒ AssemblyAI::Transcripts::Entity

Parameters:

  • entity_type (AssemblyAI::Transcripts::EntityType)

    The type of entity for the detected entity

  • text (String)

    The text for the detected entity

  • start (Integer)

    The starting time, in milliseconds, at which the detected entity appears in the audio file

  • end_ (Integer)

    The ending time, in milliseconds, for the detected entity in the audio file

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



35
36
37
38
39
40
41
42
# File 'lib/assemblyai/transcripts/types/entity.rb', line 35

def initialize(entity_type:, text:, start:, end_:, additional_properties: nil)
  @entity_type = entity_type
  @text = text
  @start = start
  @end_ = end_
  @additional_properties = additional_properties
  @_field_set = { "entity_type": entity_type, "text": text, "start": start, "end": 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



21
22
23
# File 'lib/assemblyai/transcripts/types/entity.rb', line 21

def additional_properties
  @additional_properties
end

#end_Integer (readonly)

Returns The ending time, in milliseconds, for the detected entity in the audio file.

Returns:

  • (Integer)

    The ending time, in milliseconds, for the detected entity in the audio file



19
20
21
# File 'lib/assemblyai/transcripts/types/entity.rb', line 19

def end_
  @end_
end

#entity_typeAssemblyAI::Transcripts::EntityType (readonly)

Returns The type of entity for the detected entity.

Returns:



12
13
14
# File 'lib/assemblyai/transcripts/types/entity.rb', line 12

def entity_type
  @entity_type
end

#startInteger (readonly)

Returns The starting time, in milliseconds, at which the detected entity appears in the audio file.

Returns:

  • (Integer)

    The starting time, in milliseconds, at which the detected entity appears in the audio file



17
18
19
# File 'lib/assemblyai/transcripts/types/entity.rb', line 17

def start
  @start
end

#textString (readonly)

Returns The text for the detected entity.

Returns:

  • (String)

    The text for the detected entity



14
15
16
# File 'lib/assemblyai/transcripts/types/entity.rb', line 14

def text
  @text
end

Class Method Details

.from_json(json_object:) ⇒ AssemblyAI::Transcripts::Entity

Deserialize a JSON object to an instance of Entity

Parameters:

  • json_object (String)

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/assemblyai/transcripts/types/entity.rb', line 48

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  entity_type = struct["entity_type"]
  text = struct["text"]
  start = struct["start"]
  end_ = struct["end"]
  new(
    entity_type: entity_type,
    text: text,
    start: start,
    end_: end_,
    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)


76
77
78
79
80
81
# File 'lib/assemblyai/transcripts/types/entity.rb', line 76

def self.validate_raw(obj:)
  obj.entity_type.is_a?(AssemblyAI::Transcripts::EntityType) != false || raise("Passed value for field obj.entity_type is not the expected type, validation failed.")
  obj.text.is_a?(String) != false || raise("Passed value for field obj.text is not the expected type, validation failed.")
  obj.start.is_a?(Integer) != false || raise("Passed value for field obj.start is not the expected type, validation failed.")
  obj.end_.is_a?(Integer) != false || raise("Passed value for field obj.end_ is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Entity to a JSON object

Returns:

  • (String)


66
67
68
# File 'lib/assemblyai/transcripts/types/entity.rb', line 66

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