class Skygrepe::Context
Attributes
count[R]
current_id[R]
limit[R]
Public Class Methods
new(keyword, config)
click to toggle source
# File lib/skygrepe.rb, line 12 def initialize(keyword, config) raise ArgumentError, "keyword is empty" if keyword.nil? || keyword.empty? @keyword = keyword @config = config @condition = Condition.new(@keyword) @offset = 0 @limit = 30 @quit = false @current_id = nil end
Public Instance Methods
db()
click to toggle source
# File lib/skygrepe.rb, line 27 def db @db ||= SQLite3::Database.new(@config["main_db_path"]) end
detail(id)
click to toggle source
# File lib/skygrepe.rb, line 56 def detail(id) sql = "SELECT m.id, m.timestamp, c.displayname, m.author, m.body_xml FROM Messages as m inner join Conversations as c on m.convo_id = c.id" sql << " WHERE m.id = #{id}" if d = db.execute(sql).first @current_id = d.first.to_i formatter.detail(d) else nil end end
formatter()
click to toggle source
# File lib/skygrepe.rb, line 31 def formatter @formatter ||= Formatter.new(@keyword, {"time_format" => @config["time_format"]}) end
next_detail(d = 1)
click to toggle source
# File lib/skygrepe.rb, line 67 def next_detail(d = 1) detail(@current_id + d) end
next_page(page = 1)
click to toggle source
# File lib/skygrepe.rb, line 48 def next_page(page = 1) @offset += (@limit * page) end
prev_detail(d = 1)
click to toggle source
# File lib/skygrepe.rb, line 71 def prev_detail(d = 1) self.next_detail( -1 * d) end
prev_page(page = 1)
click to toggle source
# File lib/skygrepe.rb, line 52 def prev_page(page = 1) self.next_page( -1 * page) end
quit()
click to toggle source
# File lib/skygrepe.rb, line 75 def quit @quit = true end
quit?()
click to toggle source
# File lib/skygrepe.rb, line 23 def quit? @quit end
run()
click to toggle source
# File lib/skygrepe.rb, line 35 def run @count ||= db.execute(@condition.count_sql).flatten.first.to_i sql = @condition.grep_sql(@limit, @offset) rows = db.execute(sql).map{|row| formatter.list(row) } unless rows.empty? @current_id = rows.first.first.to_i end if @count <= @limit @quit = true end rows end