Class: Pressroom::Blocks::TextExtractor
- Inherits:
-
Object
- Object
- Pressroom::Blocks::TextExtractor
- Defined in:
- lib/pressroom/blocks/text_extractor.rb
Overview
Produces plain text for the host application's search index.
Never raises: it runs inside a save callback, and a block type the registry has not seen must not prevent an author from saving a draft.
Instance Method Summary collapse
- #extract(document) ⇒ Object
-
#initialize(registry:) ⇒ TextExtractor
constructor
A new instance of TextExtractor.
Constructor Details
#initialize(registry:) ⇒ TextExtractor
Returns a new instance of TextExtractor.
10 11 12 |
# File 'lib/pressroom/blocks/text_extractor.rb', line 10 def initialize(registry:) @registry = registry end |
Instance Method Details
#extract(document) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/pressroom/blocks/text_extractor.rb', line 14 def extract(document) blocks_of(document) .filter_map { |block| text_for_block(block) } .join(" ") .gsub(/\s+/, " ") .strip end |