Class: Html2rss::Selectors::PostProcessors::ParseTime

Inherits:
Base
  • Object
show all
Defined in:
lib/html2rss/selectors/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::Selectors::PostProcessors::Base

Class Method Details

.time_zone(context) ⇒ String?

Returns configured channel time zone.

Parameters:

Returns:

  • (String, nil)

    configured channel time zone



46
# File 'lib/html2rss/selectors/post_processors/parse_time.rb', line 46

def self.time_zone(context) = context.dig(:config, :channel, :time_zone)

.validate_args!(value, context) ⇒ void

This method returns an undefined value.

Parameters:

  • value (String)

    extracted selector value

  • context (Selectors::Context)

    post-processor context



33
34
35
36
37
38
39
40
41
42
# File 'lib/html2rss/selectors/post_processors/parse_time.rb', line 33

def self.validate_args!(value, context)
  assert_type(value, String, :value, context:)
  time_zone_value = time_zone(context)

  if time_zone_value.nil? || time_zone_value.empty?
    raise ArgumentError, 'time_zone cannot be nil or empty', [], cause: nil
  end

  assert_type(time_zone_value, 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



53
54
55
# File 'lib/html2rss/selectors/post_processors/parse_time.rb', line 53

def get
  with_timezone(time_zone) { Time.parse(value).rfc822 }
end