Class: RequestHandler::PageHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/request_handler/page_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(params:, page_config:) ⇒ PageHandler

Returns a new instance of PageHandler.

Raises:



5
6
7
8
9
10
11
12
13
# File 'lib/request_handler/page_handler.rb', line 5

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 ExternalArgumentError, page: 'must be a Hash' unless @page_options.is_a?(Hash)
  @config = page_config
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/request_handler/page_handler.rb', line 15

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