Class: Daygram::Database
- Inherits:
-
Object
- Object
- Daygram::Database
- Defined in:
- lib/daygram/database.rb,
lib/daygram/database/dataset.rb
Defined Under Namespace
Classes: Dataset
Instance Method Summary collapse
- #all ⇒ Object
- #day(date) ⇒ Object
-
#initialize(options = {}, config = {}) ⇒ Database
constructor
A new instance of Database.
- #last(n) ⇒ Object
- #latest ⇒ Object
Constructor Details
#initialize(options = {}, config = {}) ⇒ Database
Returns a new instance of Database.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/daygram/database.rb', line 6 def initialize = {}, config = {} @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 |
Instance Method Details
#all ⇒ Object
32 33 34 |
# File 'lib/daygram/database.rb', line 32 def all Dataset.new(@DB[:diary].order(:date)) end |
#day(date) ⇒ Object
36 37 38 |
# File 'lib/daygram/database.rb', line 36 def day date Dataset.new(@DB[:diary].where("date == '#{date}'")) end |
#last(n) ⇒ Object
24 25 26 |
# File 'lib/daygram/database.rb', line 24 def last n Dataset.new(@DB[:diary].order(:date).reverse.limit(n)) end |
#latest ⇒ Object
28 29 30 |
# File 'lib/daygram/database.rb', line 28 def latest last 1 end |