Class: GuardianSearcher::Options
- Inherits:
-
Hash
- Object
- Hash
- GuardianSearcher::Options
show all
- Defined in:
- lib/guardian_searcher/options.rb
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ Options
Returns a new instance of Options.
13
14
15
16
17
|
# File 'lib/guardian_searcher/options.rb', line 13
def initialize(options)
raise OptionsNotHashError unless options.is_a?(Hash)
@options = options
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &blk) ⇒ Object
7
8
9
10
11
|
# File 'lib/guardian_searcher/options.rb', line 7
def method_missing(method_name, *args, &blk)
return options.[](method_name, &blk) if @options.key?(method_name)
super(method_name, *args, &blk)
end
|
Instance Method Details
#build_options ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/guardian_searcher/options.rb', line 19
def build_options
return {} if options.empty?
opt = ""
options.each do |key, value|
valid_option?(key)
opt += "&#{map_option(key)}=#{value}"
end
end
|
#map_option(key) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/guardian_searcher/options.rb', line 33
def map_option(key)
{
from_date: "from-date",
to_date: "to-date",
page_size: "page-size",
page: "page"
}[key]
end
|
#valid_option?(option) ⇒ Boolean
29
30
31
|
# File 'lib/guardian_searcher/options.rb', line 29
def valid_option?(option)
raise OptionsNotSupportedError unless %i[from_date to_date page_size page].include?(option)
end
|