Class: AssemblyAI::Realtime::Word

Inherits:
Object
  • Object
show all
Defined in:
lib/assemblyai/realtime/types/word.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start:, end_:, confidence:, text:, additional_properties: nil) ⇒ AssemblyAI::Realtime::Word

Parameters:

  • start (Integer)

    Start time of the word in milliseconds

  • end_ (Integer)

    End time of the word in milliseconds

  • confidence (Float)

    Confidence score of the word

  • text (String)

    The word itself

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



31
32
33
34
35
36
37
38
# File 'lib/assemblyai/realtime/types/word.rb', line 31

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



18
19
20
# File 'lib/assemblyai/realtime/types/word.rb', line 18

def additional_properties
  @additional_properties
end

#confidenceFloat (readonly)

Returns Confidence score of the word.

Returns:

  • (Float)

    Confidence score of the word



14
15
16
# File 'lib/assemblyai/realtime/types/word.rb', line 14

def confidence
  @confidence
end

#end_Integer (readonly)

Returns End time of the word in milliseconds.

Returns:

  • (Integer)

    End time of the word in milliseconds



12
13
14
# File 'lib/assemblyai/realtime/types/word.rb', line 12

def end_
  @end_
end

#startInteger (readonly)

Returns Start time of the word in milliseconds.

Returns:

  • (Integer)

    Start time of the word in milliseconds



10
11
12
# File 'lib/assemblyai/realtime/types/word.rb', line 10

def start
  @start
end

#textString (readonly)

Returns The word itself.

Returns:

  • (String)

    The word itself



16
17
18
# File 'lib/assemblyai/realtime/types/word.rb', line 16

def text
  @text
end

Class Method Details

.from_json(json_object:) ⇒ AssemblyAI::Realtime::Word

Deserialize a JSON object to an instance of Word

Parameters:

  • json_object (String)

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/assemblyai/realtime/types/word.rb', line 44

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


72
73
74
75
76
77
# File 'lib/assemblyai/realtime/types/word.rb', line 72

def self.validate_raw(obj:)
  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.")
  obj.confidence.is_a?(Float) != false || raise("Passed value for field obj.confidence 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.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Word to a JSON object

Returns:

  • (String)


62
63
64
# File 'lib/assemblyai/realtime/types/word.rb', line 62

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