class Daygram::Database

Public Class Methods

new(options = {}) click to toggle source
# File lib/daygram/database.rb, line 6
def initialize options = {}, config = {}
  @options = options
  @config = config
  if @options[:database]
    path = @options[:database]
  elsif config.to_h["database"]
    path = @config.to_h["database"]
  else
    raise "Must specify the database location"
  end

  unless File.exists? path
    raise "Specified DB does not exist: #{path}"
  end

  @DB = Sequel.sqlite(path)
end

Public Instance Methods

all() click to toggle source
# File lib/daygram/database.rb, line 32
def all
  Dataset.new(@DB[:diary].order(:date))
end
day(date) click to toggle source
# File lib/daygram/database.rb, line 36
def day date
  Dataset.new(@DB[:diary].where("date == '#{date}'"))
end
last(n) click to toggle source
# File lib/daygram/database.rb, line 24
def last n
  Dataset.new(@DB[:diary].order(:date).reverse.limit(n))
end
latest() click to toggle source
# File lib/daygram/database.rb, line 28
def latest
  last 1
end