Class: Html2rss::Selectors::Extractors::Text
- Inherits:
-
Object
- Object
- Html2rss::Selectors::Extractors::Text
- Defined in:
- lib/html2rss/selectors/extractors/text.rb
Overview
Return the text content of the attribute. This is the default extractor used, when no extractor is explicitly given.
Example HTML structure:
<p>Lorem <b>ipsum</b> dolor ...</p>
YAML usage example:
selectors:
description:
selector: p
extractor: text
Would return:
'Lorem ipsum dolor ...'
Defined Under Namespace
Classes: Options
Constant Summary collapse
- DESCRIPTION =
JSON Schema description exported via
schema_doc. 'Return collapsed visible text of the selected element (default extractor).'- EXAMPLES =
Example extractor name values for JSON Schema
examples. [ 'text' ].freeze
Class Method Summary collapse
-
.schema_doc ⇒ Hash{Symbol => Object}
JSON Schema fragment for this extractor name.
Instance Method Summary collapse
-
#get ⇒ String
Retrieves and returns the text content of the element.
-
#initialize(xml, options) ⇒ Text
constructor
Initializes the Text extractor.
Constructor Details
#initialize(xml, options) ⇒ Text
Initializes the Text extractor.
44 45 46 |
# File 'lib/html2rss/selectors/extractors/text.rb', line 44 def initialize(xml, ) @element = Extractors.element(xml, .selector) end |
Class Method Details
.schema_doc ⇒ Hash{Symbol => Object}
Returns JSON Schema fragment for this extractor name.
36 |
# File 'lib/html2rss/selectors/extractors/text.rb', line 36 def self.schema_doc = SchemaDoc.for_extractor(name: :text, klass: self) |
Instance Method Details
#get ⇒ String
Retrieves and returns the text content of the element.
52 53 54 |
# File 'lib/html2rss/selectors/extractors/text.rb', line 52 def get @element.text.to_s.strip.gsub(/\s+/, ' ') end |