Class: Html2rss::Selectors::PostProcessors::ParseTime
- 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
Class Method Summary collapse
Instance Method Summary collapse
-
#get ⇒ String
Converts the provided time string to RFC822 format, taking into account the time_zone.
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) ⇒ Object
41 |
# File 'lib/html2rss/selectors/post_processors/parse_time.rb', line 41 def self.time_zone(context) = context.dig(:config, :channel, :time_zone) |
.validate_args!(value, context) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/html2rss/selectors/post_processors/parse_time.rb', line 30 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
#get ⇒ String
Converts the provided time string to RFC822 format, taking into account the time_zone.
48 49 50 |
# File 'lib/html2rss/selectors/post_processors/parse_time.rb', line 48 def get with_timezone(time_zone) { Time.parse(value).rfc822 } end |