Sha256: d272a5b2f411f90feacbb9c07c3ab5dba8377077d1827d9e2b1b806b0160af03

Contents?: true

Size: 802 Bytes

Versions: 7

Compression:

Stored size: 802 Bytes

Contents

module Html2rss
  module AttributePostProcessors
    ## 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'
    class Substring
      def initialize(value, env)
        @value = value
        @options = env[:options]
      end

      ##
      # @return [String]
      def get
        ending = @options.fetch('end', @value.length).to_i
        @value[@options['start'].to_i..ending]
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
html2rss-0.7.0 lib/html2rss/attribute_post_processors/substring.rb
html2rss-0.6.0 lib/html2rss/attribute_post_processors/substring.rb
html2rss-0.5.2 lib/html2rss/attribute_post_processors/substring.rb
html2rss-0.5.1 lib/html2rss/attribute_post_processors/substring.rb
html2rss-0.5.0 lib/html2rss/attribute_post_processors/substring.rb
html2rss-0.4.1 lib/html2rss/attribute_post_processors/substring.rb
html2rss-0.4.0 lib/html2rss/attribute_post_processors/substring.rb