Class: Cliptic::Database::Recents

Inherits:
SQL
  • Object
show all
Defined in:
lib/cliptic/database.rb

Instance Attribute Summary collapse

Attributes inherited from SQL

#db, #table

Instance Method Summary collapse

Methods inherited from SQL

#delete, #drop, #insert, #make_table, #select, #update

Constructor Details

#initializeRecents

Returns a new instance of Recents.



184
185
186
# File 'lib/cliptic/database.rb', line 184

def initialize
  super(table:"recents").make_table
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



183
184
185
# File 'lib/cliptic/database.rb', line 183

def date
  @date
end

Instance Method Details

#add(date:) ⇒ Object



197
198
199
200
# File 'lib/cliptic/database.rb', line 197

def add(date:)
  @date = date
  exists? ? add_existing : add_new
end

#add_existingObject



207
208
209
# File 'lib/cliptic/database.rb', line 207

def add_existing
  update(values:build, where:{date:date.to_s})
end

#add_newObject



204
205
206
# File 'lib/cliptic/database.rb', line 204

def add_new
  insert(values:build)
end

#buildObject



210
211
212
213
214
215
216
# File 'lib/cliptic/database.rb', line 210

def build
  {
    date:      date.to_s,
    play_date: Date.today.to_s,
    play_time: Time.now.strftime("%T")
  }
end

#colsObject



187
188
189
190
191
192
193
# File 'lib/cliptic/database.rb', line 187

def cols
  {
    date: :DATE,
    play_date: :DATE,
    play_time: :TIME
  }
end

#exists?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/cliptic/database.rb', line 201

def exists?
  select(where:{date:date.to_s}).count > 0
end

#select_listObject



194
195
196
# File 'lib/cliptic/database.rb', line 194

def select_list
  select(cols:"*", order:{play_date:"DESC", play_time:"DESC"}, limit:10)
end