Class: LangExtract::Core::Document
- Inherits:
-
Object
- Object
- LangExtract::Core::Document
- Defined in:
- lib/langextract/core/data.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text:, id: nil, metadata: {}) ⇒ Document
constructor
A new instance of Document.
- #to_h ⇒ Object
Constructor Details
#initialize(text:, id: nil, metadata: {}) ⇒ Document
Returns a new instance of Document.
168 169 170 171 172 173 174 175 |
# File 'lib/langextract/core/data.rb', line 168 def initialize(text:, id: nil, metadata: {}) raise ArgumentError, "text is required" if text.nil? @text = text @id = id @metadata = HashCoercion.stringify_keys().freeze freeze end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
166 167 168 |
# File 'lib/langextract/core/data.rb', line 166 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
166 167 168 |
# File 'lib/langextract/core/data.rb', line 166 def @metadata end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
166 167 168 |
# File 'lib/langextract/core/data.rb', line 166 def text @text end |
Class Method Details
.from_h(hash) ⇒ Object
181 182 183 184 185 186 187 |
# File 'lib/langextract/core/data.rb', line 181 def self.from_h(hash) new( id: HashCoercion.read(hash, :id), text: HashCoercion.read(hash, :text).to_s, metadata: HashCoercion.read(hash, :metadata) || {} ) end |
Instance Method Details
#to_h ⇒ Object
177 178 179 |
# File 'lib/langextract/core/data.rb', line 177 def to_h { "id" => id, "text" => text, "metadata" => } end |