Class: Html2rss::AttributePostProcessors::Base
- Inherits:
-
Object
- Object
- Html2rss::AttributePostProcessors::Base
- Defined in:
- lib/html2rss/attribute_post_processors/base.rb
Overview
All post processors must inherit from this base class and implement ‘self.validate_args!` and `#get`.
Direct Known Subclasses
Gsub, HtmlToMarkdown, MarkdownToHtml, ParseTime, ParseUri, SanitizeHtml, Substring, Template
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.assert_type(value, types = [], name, context:) ⇒ Object
Asserts that the value is of the expected type(s).
-
.expect_options(keys, context) ⇒ Object
Validates the presence of required options in the context.
-
.validate_args!(_value, _context) ⇒ Object
This method validates the arguments passed to the post processor.
Instance Method Summary collapse
-
#get ⇒ Object
Abstract method to be implemented by subclasses.
-
#initialize(value, context) ⇒ Base
constructor
Initializes the post processor.
Constructor Details
#initialize(value, context) ⇒ Base
Initializes the post processor
54 55 56 57 58 59 60 61 62 |
# File 'lib/html2rss/attribute_post_processors/base.rb', line 54 def initialize(value, context) klass = self.class # TODO: get rid of Hash klass.assert_type(context, [Item::Context, Hash], 'context', context:) klass.validate_args!(value, context) @value = value @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
64 65 66 |
# File 'lib/html2rss/attribute_post_processors/base.rb', line 64 def context @context end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
64 65 66 |
# File 'lib/html2rss/attribute_post_processors/base.rb', line 64 def value @value end |
Class Method Details
.assert_type(value, types = [], name, context:) ⇒ Object
Asserts that the value is of the expected type(s)
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/html2rss/attribute_post_processors/base.rb', line 31 def self.assert_type(value, types = [], name, context:) types = [types] unless types.is_a?(Array) return if types.any? { |type| value.is_a?(type) } = context[:options] if context.is_a?(Hash) ||= { file: File.basename(caller_locations(1, 1).first.absolute_path) } raise InvalidType, format('The type of `%<name>s` must be %<types>s, but is: %<type>s in: %<options>s', name:, types: types.join(' or '), type: value.class, options: .inspect), [], cause: nil end |
.expect_options(keys, context) ⇒ Object
Validates the presence of required options in the context
15 16 17 18 19 20 21 22 |
# File 'lib/html2rss/attribute_post_processors/base.rb', line 15 def self.(keys, context) keys.each do |key| unless ( = context[:options]).key?(key) raise MissingOption, "The `#{key}` option is missing in: #{.inspect}", [], cause: nil end end end |
.validate_args!(_value, _context) ⇒ Object
This method validates the arguments passed to the post processor. Must be implemented by subclasses.
46 47 48 |
# File 'lib/html2rss/attribute_post_processors/base.rb', line 46 def self.validate_args!(_value, _context) raise NotImplementedError, 'You must implement the `validate_args!` method in the post processor' end |
Instance Method Details
#get ⇒ Object
Abstract method to be implemented by subclasses
69 70 71 |
# File 'lib/html2rss/attribute_post_processors/base.rb', line 69 def get raise NotImplementedError, 'You must implement the `get` method in the post processor' end |