Class: Html2rss::AttributePostProcessors::Substring
- Inherits:
-
Object
- Object
- Html2rss::AttributePostProcessors::Substring
- Defined in:
- lib/html2rss/attribute_post_processors/substring.rb
Overview
Returns a defined part of a String.
The end
parameter can be omitted, in that case it will not cut the String at the end.
Imagine this HTML:
<h1>Foo bar and baz<h1>
YAML usage example:
selectors:
title:
selector: h1
post_process:
name: substring
start: 4
end: 6
Would return:
'bar'
Instance Method Summary collapse
- #get ⇒ String
-
#initialize(value, options, _item) ⇒ Substring
constructor
A new instance of Substring.
Constructor Details
#initialize(value, options, _item) ⇒ Substring
Returns a new instance of Substring
23 24 25 26 |
# File 'lib/html2rss/attribute_post_processors/substring.rb', line 23 def initialize(value, , _item) @value = value @options = end |
Instance Method Details
#get ⇒ String
30 31 32 33 |
# File 'lib/html2rss/attribute_post_processors/substring.rb', line 30 def get ending = @options.fetch('end', @value.length).to_i @value[@options['start'].to_i..ending] end |