Class: Html2rss::AttributePostProcessors::ParseTime

Inherits:
Object
  • 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 Method Summary collapse

Constructor Details

#initialize(value, env) ⇒ ParseTime

Returns a new instance of ParseTime.



27
28
29
30
# File 'lib/html2rss/attribute_post_processors/parse_time.rb', line 27

def initialize(value, env)
  @value = value.to_s
  @time_zone = env[:config].time_zone
end

Instance Method Details

#getString

Returns rfc822 formatted time.

Returns:

  • (String)

    rfc822 formatted time



34
35
36
# File 'lib/html2rss/attribute_post_processors/parse_time.rb', line 34

def get
  Time.use_zone(@time_zone) { Time.zone.parse(@value).rfc822 }
end