Sha256: 3038648e2c605152de3f68b132ec5e063458155757735ecc7586e21605127e30

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

require 'active_support'
require 'active_support/core_ext/time'

module Html2rss
  module AttributePostProcessors
    ##
    # Returns the {https://www.w3.org/Protocols/rfc822/ RFC822} representation of a time.
    #
    # Imagine this HTML structure:
    #
    #     <p>Published on <span>2019-07-02</span></p>
    #
    # YAML usage example:
    #
    #    selectors:
    #      description:
    #        selector: span
    #        post_process:
    #          name: 'parse_time'
    #
    # Would return:
    #    "Tue, 02 Jul 2019 00:00:00 +0200"
    #
    # It uses {https://ruby-doc.org/stdlib-2.5.3/libdoc/time/rdoc/Time.html#method-c-parse Time.parse}.
    # As of now it ignores time zones and always falls back to the UTC time zone.
    class ParseTime
      def initialize(value, env)
        @value = value.to_s
        @time_zone = env[:config].time_zone
      end

      ##
      # @return [String] rfc822 formatted time
      def get
        Time.use_zone(@time_zone) { Time.zone.parse(@value).rfc822 }
      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/parse_time.rb
html2rss-0.6.0 lib/html2rss/attribute_post_processors/parse_time.rb
html2rss-0.5.2 lib/html2rss/attribute_post_processors/parse_time.rb
html2rss-0.5.1 lib/html2rss/attribute_post_processors/parse_time.rb
html2rss-0.5.0 lib/html2rss/attribute_post_processors/parse_time.rb
html2rss-0.4.1 lib/html2rss/attribute_post_processors/parse_time.rb
html2rss-0.4.0 lib/html2rss/attribute_post_processors/parse_time.rb