Class: Giblish::SearchQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/giblish/search/searchquery.rb

Constant Summary collapse

REQUIRED_PARAMS =
%w[calling-url search-assets-top-rel search-phrase]
OPTIONAL_PARAMS =
%w[css-path consider-case as-regexp]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri: nil, query_params: nil) ⇒ SearchQuery

Returns a new instance of SearchQuery.



8
9
10
11
12
13
14
15
16
17
# File 'lib/giblish/search/searchquery.rb', line 8

def initialize(uri: nil, query_params: nil)
  @parameters = case [uri, query_params]
  in [String, nil]
    uri_2_params(uri)
  in [nil, _]
    validate_parameters(query_params)
  else
    raise ArgumentError, "You must supply one of 'uri: [String]' or 'query_params: [Hash]' got: #{query_params}"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/giblish/search/searchquery.rb', line 36

def method_missing(meth, *args, &block)
  unless respond_to_missing?(meth)
    super(meth, *args, &block)
    return
  end

  @parameters[meth.to_s.tr("_", "-")]
end

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.



3
4
5
# File 'lib/giblish/search/searchquery.rb', line 3

def parameters
  @parameters
end

Instance Method Details

#as_regexp?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/giblish/search/searchquery.rb', line 32

def as_regexp?
  @parameters.key?("as-regexp")
end

#consider_case?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/giblish/search/searchquery.rb', line 28

def consider_case?
  @parameters.key?("consider-case")
end

#css_pathObject



19
20
21
# File 'lib/giblish/search/searchquery.rb', line 19

def css_path
  @parameters.key?("css-path") && !@parameters["css-path"].empty? ? Pathname.new(@parameters["css-path"]) : nil
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/giblish/search/searchquery.rb', line 45

def respond_to_missing?(method_name, include_private = false)
  @parameters.key?(method_name.to_s.tr("_", "-"))
end

#search_assets_top_relObject



23
24
25
26
# File 'lib/giblish/search/searchquery.rb', line 23

def search_assets_top_rel
  # convert to pathname and make sure we always are relative
  Pathname.new("./" + @parameters["search-assets-top-rel"]).cleanpath
end