Class: Cliptic::Database::State

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

Direct Known Subclasses

Stats

Constant Summary

Constants included from Chars

Chars::Block, Chars::HL, Chars::LL, Chars::LS, Chars::LU, Chars::MS, Chars::Nums, Chars::RL, Chars::RS, Chars::RU, Chars::TD, Chars::TL, Chars::TR, Chars::TU, Chars::Tick, Chars::VL, Chars::XX

Instance Attribute Summary collapse

Attributes inherited from SQL

#db, #table

Instance Method Summary collapse

Methods included from Chars

small_num

Methods inherited from SQL

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

Constructor Details

#initialize(date: Date.today) ⇒ State

Returns a new instance of State.



95
96
97
98
99
# File 'lib/cliptic/database.rb', line 95

def initialize(date:Date.today)
  super(table:"states").make_table
  @date = date
  set
end

Instance Attribute Details

#charsObject (readonly)

Returns the value of attribute chars.



92
93
94
# File 'lib/cliptic/database.rb', line 92

def chars
  @chars
end

#dateObject (readonly)

Returns the value of attribute date.



92
93
94
# File 'lib/cliptic/database.rb', line 92

def date
  @date
end

#doneObject (readonly)

Returns the value of attribute done.



92
93
94
# File 'lib/cliptic/database.rb', line 92

def done
  @done
end

#n_doneObject (readonly)

Returns the value of attribute n_done.



92
93
94
# File 'lib/cliptic/database.rb', line 92

def n_done
  @n_done
end

#n_totObject (readonly)

Returns the value of attribute n_tot.



92
93
94
# File 'lib/cliptic/database.rb', line 92

def n_tot
  @n_tot
end

#revealsObject

Returns the value of attribute reveals.



92
93
94
# File 'lib/cliptic/database.rb', line 92

def reveals
  @reveals
end

#timeObject (readonly)

Returns the value of attribute time.



92
93
94
# File 'lib/cliptic/database.rb', line 92

def time
  @time
end

Instance Method Details

#colsObject



100
101
102
103
104
105
106
# File 'lib/cliptic/database.rb', line 100

def cols
  {
    date: :DATE, time: :INT, chars: :TEXT, 
    n_done: :INT, n_tot: :INT, reveals: :INT, 
    done: :INT
  }
end

#deleteObject



113
114
115
116
117
# File 'lib/cliptic/database.rb', line 113

def delete
  super(where:{date:date.to_s})
  @exists = false
  set
end

#exists?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/cliptic/database.rb', line 107

def exists?
  @exists || query.count > 0
end

#save(game:) ⇒ Object



110
111
112
# File 'lib/cliptic/database.rb', line 110

def save(game:)
  exists? ? save_existing(game) : save_new(game)
end