Class: Giblish::SearchDataRepo

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

Overview

Provides access to all search related info for one tree of adoc src docs.

Constant Summary collapse

SEARCH_DB_BASENAME =
"heading_db.json"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(assets_fs_path) ⇒ SearchDataRepo

assets_uri_path

a Pathname to the top dir of the search asset folder



180
181
182
183
184
# File 'lib/giblish/search/textsearcher.rb', line 180

def initialize(assets_fs_path)
  @assets_fs_path = assets_fs_path
  @search_db = read_search_db
  @src_tree = build_src_tree
end

Instance Attribute Details

#db_mod_timeObject (readonly)

Returns the value of attribute db_mod_time.



175
176
177
# File 'lib/giblish/search/textsearcher.rb', line 175

def db_mod_time
  @db_mod_time
end

#search_dbObject (readonly)

Returns the value of attribute search_db.



175
176
177
# File 'lib/giblish/search/textsearcher.rb', line 175

def search_db
  @search_db
end

#src_treeObject (readonly)

Returns the value of attribute src_tree.



175
176
177
# File 'lib/giblish/search/textsearcher.rb', line 175

def src_tree
  @src_tree
end

Instance Method Details

#in_section(filepath, line_no) ⇒ Object

find section with closest lower line_no to line_info NOTE: line_no in is 1-based



188
189
190
191
# File 'lib/giblish/search/textsearcher.rb', line 188

def in_section(filepath, line_no)
  i = info(filepath)
  i[:sections].reverse.find { |section| line_no >= section[:line_no] }
end

#info(filepath) ⇒ Object

return

the info from the repo for the given filepath or nil if no info exists



195
196
197
# File 'lib/giblish/search/textsearcher.rb', line 195

def info(filepath)
  @search_db[:fileinfos].find { |info| info[:filepath] == filepath.to_s }
end

#is_staleObject



199
200
201
# File 'lib/giblish/search/textsearcher.rb', line 199

def is_stale
  @db_mod_time != File.stat(db_filepath.to_s).mtime
end