Class: Giblish::SearchParameters

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

Overview

Encapsulates raw data and information deducable from one search query

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



82
83
84
85
86
# File 'lib/giblish/search/textsearcher.rb', line 82

def method_missing(meth, *args, &block)
  return @query.send(meth, *args, &block) if respond_to_missing?(meth)

  super(meth, args, &block)
end

Instance Attribute Details

#parametersObject (readonly)

a hash with { param => value } of all query parameters from the URI.



33
34
35
# File 'lib/giblish/search/textsearcher.rb', line 33

def parameters
  @parameters
end

#uriObject (readonly)

Returns the value of attribute uri.



34
35
36
# File 'lib/giblish/search/textsearcher.rb', line 34

def uri
  @uri
end

Class Method Details

.from_hash(h, uri_mappings: {"/" => "/var/www/html/"}) ⇒ Object



41
42
43
44
# File 'lib/giblish/search/textsearcher.rb', line 41

def self.from_hash(h, uri_mappings: {"/" => "/var/www/html/"})
  q = SearchQuery.new(query_params: h)
  SearchParameters.new(query: q, uri_mappings: uri_mappings)
end

.from_uri(uri_str, uri_mappings: {"/" => "/var/www/html/"}) ⇒ Object



36
37
38
39
# File 'lib/giblish/search/textsearcher.rb', line 36

def self.from_uri(uri_str, uri_mappings: {"/" => "/var/www/html/"})
  q = SearchQuery.new(uri: uri_str)
  SearchParameters.new(query: q, uri_mappings: uri_mappings)
end

Instance Method Details

#assets_fs_pathObject

return

the absolute Pathname of the file system path to the

search assets top dir.



78
79
80
# File 'lib/giblish/search/textsearcher.rb', line 78

def assets_fs_path
  uri_to_fs(assets_uri_path)
end

#assets_uri_pathObject

the URI path to the search asset directory eg: www.mysite.com/my/doc/path/subdir1/doc1.html could be assets_uri_path = my/doc/path/gibsearch_assets



54
55
56
57
# File 'lib/giblish/search/textsearcher.rb', line 54

def assets_uri_path
  @assets_uri_path ||= Pathname.new(uri_path).dirname.join(search_assets_top_rel).cleanpath
  @assets_uri_path
end

#css_pathObject

the URI path to the css file to use for styling the search result eg: www.mysite.com/my/doc/path/subdir1/doc1.html could be css_path = my/doc/path/web/mystyle.css



61
62
63
64
65
66
67
68
69
# File 'lib/giblish/search/textsearcher.rb', line 61

def css_path
  return nil if @query.css_path.nil?

  return @query.css_path if @query.css_path.absolute?

  # css paths from the query is relative, add it to the
  @css_path ||= Pathname.new(uri_path).dirname.join(@query.css_path).cleanpath
  @css_path
end

#repo_file_pathObject

return

the relative path from the doc top dir to the file



93
94
95
# File 'lib/giblish/search/textsearcher.rb', line 93

def repo_file_path
  Pathname.new(uri_path).relative_path_from(uri_path_repo_top)
end

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

Returns:

  • (Boolean)


88
89
90
# File 'lib/giblish/search/textsearcher.rb', line 88

def respond_to_missing?(meth, include_private = false)
  @query.respond_to?(meth)
end

#uri_pathObject

the fragment of the calling doc’s URI eg: www.mysite.com/my/doc/path/subdir1/doc1.html -> uri_path = my/doc/path/subdir1/doc1.html



48
49
50
# File 'lib/giblish/search/textsearcher.rb', line 48

def uri_path
  URI(calling_url).path
end

#uri_path_repo_topObject

return

the uri path pointing to the doc repo top dir



72
73
74
# File 'lib/giblish/search/textsearcher.rb', line 72

def uri_path_repo_top
  Pathname.new(uri_path).join(search_assets_top_rel.dirname).dirname
end

#url(repo_filepath, fragment = nil) ⇒ Object

repo_filepath

the filepath from the repo top to a given file

fragment

the fragment id or nil

return

the access url for a given section in a given src file



101
102
103
104
105
106
107
108
109
110
# File 'lib/giblish/search/textsearcher.rb', line 101

def url(repo_filepath, fragment = nil)
  p = Pathname.new(repo_filepath)

  # create result by replacing relevant parts of the original uri
  res = URI(@query.calling_url)
  res.query = nil
  res.fragment = fragment
  res.path = uri_path_repo_top.join(p.sub_ext(".html")).cleanpath.to_s
  res
end