Class: LangExtract::Core::ExampleData

Inherits:
Object
  • Object
show all
Defined in:
lib/langextract/core/data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, extractions:) ⇒ ExampleData

Returns a new instance of ExampleData.

Raises:

  • (ArgumentError)


230
231
232
233
234
235
236
# File 'lib/langextract/core/data.rb', line 230

def initialize(text:, extractions:)
  raise ArgumentError, "text is required" if text.nil?

  @text = text
  @extractions = extractions.map { |item| normalize_extraction(item) }.freeze
  freeze
end

Instance Attribute Details

#extractionsObject (readonly)

Returns the value of attribute extractions.



228
229
230
# File 'lib/langextract/core/data.rb', line 228

def extractions
  @extractions
end

#textObject (readonly)

Returns the value of attribute text.



228
229
230
# File 'lib/langextract/core/data.rb', line 228

def text
  @text
end

Class Method Details

.from_h(hash) ⇒ Object



245
246
247
248
249
250
# File 'lib/langextract/core/data.rb', line 245

def self.from_h(hash)
  new(
    text: HashCoercion.read(hash, :text).to_s,
    extractions: Array(HashCoercion.read(hash, :extractions))
  )
end

Instance Method Details

#to_hObject



238
239
240
241
242
243
# File 'lib/langextract/core/data.rb', line 238

def to_h
  {
    "text" => text,
    "extractions" => extractions
  }
end