Class: RequestHandler::PageParser

Inherits:
BaseParser show all
Defined in:
lib/request_handler/page_parser.rb

Instance Method Summary collapse

Methods included from Concerns::ConfigHelper

#deep_to_h, #lookup, #lookup!, #symbolize_key

Constructor Details

#initialize(params:, page_config:) ⇒ PageParser

Returns a new instance of PageParser.



8
9
10
11
12
13
14
15
16
# File 'lib/request_handler/page_parser.rb', line 8

def initialize(params:, page_config:)
  missing_arguments = []
  missing_arguments << { params: 'is missing' } if params.nil?
  missing_arguments << { page_config: 'is missing' } if page_config.nil?
  raise MissingArgumentError, missing_arguments unless missing_arguments.empty?
  @page_options = params.fetch('page') { {} }
  raise PageParamsError, page: 'must be a Hash' unless @page_options.is_a?(Hash)
  @config = page_config
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
# File 'lib/request_handler/page_parser.rb', line 18

def run
  cfg = deep_to_h(config).keys.reduce(base_page) do |memo, key|
    next memo if TOP_LEVEL_PAGE_KEYS.include?(key)
    memo.merge!("#{key}#{separator}number".to_sym => extract_number(prefix: key),
                "#{key}#{separator}size".to_sym   => extract_size(prefix: key))
  end
  check_for_missing_options(cfg)
  cfg
end