Class: Maglev::AttachmentExtractor
- Inherits:
-
Object
- Object
- Maglev::AttachmentExtractor
- Defined in:
- lib/maglev/attachment_extractor.rb
Direct Known Subclasses
Instance Method Summary collapse
- #extract(blob, source_name:) ⇒ Object
-
#initialize(allowed_content_types: Maglev.configuration.attachment_allowed_content_types, max_bytes: Maglev.configuration.attachment_max_bytes, max_characters: Maglev.configuration.attachment_max_characters) ⇒ AttachmentExtractor
constructor
A new instance of AttachmentExtractor.
Constructor Details
#initialize(allowed_content_types: Maglev.configuration.attachment_allowed_content_types, max_bytes: Maglev.configuration.attachment_max_bytes, max_characters: Maglev.configuration.attachment_max_characters) ⇒ AttachmentExtractor
Returns a new instance of AttachmentExtractor.
10 11 12 13 14 15 16 |
# File 'lib/maglev/attachment_extractor.rb', line 10 def initialize(allowed_content_types: Maglev.configuration., max_bytes: Maglev.configuration., max_characters: Maglev.configuration.) @allowed_content_types = allowed_content_types @max_bytes = max_bytes @max_characters = max_characters end |
Instance Method Details
#extract(blob, source_name:) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/maglev/attachment_extractor.rb', line 18 def extract(blob, source_name:) source_identifier = source_identifier(source_name, blob) = (blob) return skipped(source_identifier, "unsupported_content_type", ) unless allowed?(blob) return skipped(source_identifier, "size_limit", ) if too_large?(blob) text = extract_text(blob) text, truncated = truncate(text) ExtractedDocument.extracted( source_identifier: source_identifier, text: text, metadata: .merge(strategy: "deterministic", truncated: truncated) ) end |