Class: Cliptic::Database::Recents
- Inherits:
-
SQL
- Object
- SQL
- Cliptic::Database::Recents
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
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
#date ⇒ Object
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_existing ⇒ Object
207
208
209
|
# File 'lib/cliptic/database.rb', line 207
def add_existing
update(values:build, where:{date:date.to_s})
end
|
#add_new ⇒ Object
204
205
206
|
# File 'lib/cliptic/database.rb', line 204
def add_new
insert(values:build)
end
|
#build ⇒ Object
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
|
#cols ⇒ Object
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
201
202
203
|
# File 'lib/cliptic/database.rb', line 201
def exists?
select(where:{date:date.to_s}).count > 0
end
|
#select_list ⇒ Object
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
|