Class: Html2rss::AttributePostProcessors::ParseTime

Inherits:
Base
  • Object
show all
Defined in:
lib/html2rss/attribute_post_processors/parse_time.rb

Overview

Returns the / 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'
      time_zone: 'Europe/Berlin'

Would return:

"Tue, 02 Jul 2019 00:00:00 +0200"

It uses ‘Time.parse`.

Instance Attribute Summary

Attributes inherited from Base

#context, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

assert_type, expect_options, #initialize

Constructor Details

This class inherits a constructor from Html2rss::AttributePostProcessors::Base

Class Method Details

.validate_args!(value, context) ⇒ Object



29
30
31
32
# File 'lib/html2rss/attribute_post_processors/parse_time.rb', line 29

def self.validate_args!(value, context)
  assert_type(value, String, :value, context:)
  assert_type(context[:config].time_zone, String, :time_zone, context:)
end

Instance Method Details

#getString

Converts the provided time string to RFC822 format, taking into account the time_zone.

Returns:

  • (String)

    RFC822 formatted time

Raises:

  • (TZInfo::InvalidTimezoneIdentifier)

    if the configured time zone is invalid



39
40
41
42
43
# File 'lib/html2rss/attribute_post_processors/parse_time.rb', line 39

def get
  time_zone = context[:config].time_zone

  Utils.use_zone(time_zone) { Time.parse(value).rfc822 }
end