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:
Published on 2019-07-02
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.
Constant Summary collapse
- DESCRIPTION =
JSON Schema description exported via
schema_doc. 'Parse a time string with Time.parse and return RFC822, using the channel `time_zone`.'- EXAMPLES =
Example post-process objects for JSON Schema
examples. [ { 'name' => 'parse_time' } ].freeze
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.schema_doc ⇒ Hash{Symbol => Object}
JSON Schema fragment for this post-processor.
-
.time_zone(context) ⇒ String?
Configured channel time zone.
- .validate_args!(value, context) ⇒ void
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
.schema_doc ⇒ Hash{Symbol => Object}
Returns JSON Schema fragment for this post-processor.
39 |
# File 'lib/html2rss/selectors/post_processors/parse_time.rb', line 39 def self.schema_doc = SchemaDoc.for_post_processor(name: :parse_time, klass: self) |
.time_zone(context) ⇒ String?
Returns configured channel time zone.
57 |
# File 'lib/html2rss/selectors/post_processors/parse_time.rb', line 57 def self.time_zone(context) = context.dig(:config, :channel, :time_zone) |
.validate_args!(value, context) ⇒ void
This method returns an undefined value.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/html2rss/selectors/post_processors/parse_time.rb', line 44 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.
64 65 66 |
# File 'lib/html2rss/selectors/post_processors/parse_time.rb', line 64 def get with_timezone(time_zone) { Time.parse(value).rfc822 } end |