Class: OmahSearch
- Inherits:
-
Object
- Object
- OmahSearch
- Defined in:
- lib/omah_search.rb
Instance Method Summary collapse
-
#initialize(db_file = 'headers.db', url_base: nil, limit: 20) ⇒ OmahSearch
constructor
A new instance of OmahSearch.
- #search(keyword) ⇒ Object
Constructor Details
#initialize(db_file = 'headers.db', url_base: nil, limit: 20) ⇒ OmahSearch
Returns a new instance of OmahSearch.
11 12 13 14 15 16 17 |
# File 'lib/omah_search.rb', line 11 def initialize(db_file='headers.db', url_base: nil, limit: 20) @rs = RecordxSqlite.new(db_file) @url_base = url_base @limit = limit end |
Instance Method Details
#search(keyword) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/omah_search.rb', line 19 def search(keyword) @rs.query( "select date, from_x, to_x, subject, filepath from headers " + "where from_x like '%#{keyword}%' " + "or subject like '%#{keyword}%' order by id desc limit #{@limit}" + " COLLATE NOCASE") a = @rs.all.map do |x| { date: x.date[/^[^T]+/], from: x.from_x, to: x.to_x, subject: x.subject, url: "[link](%s%s)" % [@url_base, x.filepath] } end dx = Dynarex.new dx.import a table = dx.to_table table.labels = %w(date from to subject link) table.markdown = true table end |