Class: LangExtract::Core::ExampleData
- Inherits:
-
Object
- Object
- LangExtract::Core::ExampleData
- Defined in:
- lib/langextract/core/data.rb
Instance Attribute Summary collapse
-
#extractions ⇒ Object
readonly
Returns the value of attribute extractions.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text:, extractions:) ⇒ ExampleData
constructor
A new instance of ExampleData.
- #to_h ⇒ Object
Constructor Details
#initialize(text:, extractions:) ⇒ ExampleData
Returns a new instance of ExampleData.
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
#extractions ⇒ Object (readonly)
Returns the value of attribute extractions.
228 229 230 |
# File 'lib/langextract/core/data.rb', line 228 def extractions @extractions end |
#text ⇒ Object (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_h ⇒ Object
238 239 240 241 242 243 |
# File 'lib/langextract/core/data.rb', line 238 def to_h { "text" => text, "extractions" => extractions } end |