Class: EZTop10
- Inherits:
-
Object
- Object
- EZTop10
- Defined in:
- lib/EZTOP10.rb
Instance Method Summary collapse
- #AddWords(words) ⇒ Object
- #getTOP10 ⇒ Object
-
#initialize(db) ⇒ EZTop10
constructor
A new instance of EZTop10.
Constructor Details
#initialize(db) ⇒ EZTop10
Returns a new instance of EZTop10.
4 5 6 7 8 |
# File 'lib/EZTOP10.rb', line 4 def initialize(db) $dbase= SQLite3::Database.new(db) $dbase.execute("CREATE TABLE IF NOT EXISTS EZTop10(Id INTEGER PRIMARY KEY, word VARCHAR Unique, amount INTEGER)") end |
Instance Method Details
#AddWords(words) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/EZTOP10.rb', line 23 def AddWords(words) if(words.kind_of?(Array)) for i in 0..words.count-1 row = $dbase.get_first_row( "select amount from EZTop10 WHERE word='#{words[i]}'" ) if(row==nil) $dbase.execute("insert into EZTop10 (word,amount) values('#{words[i]}',1)") else @val = row[0] + 1 $dbase.execute("UPDATE EZTop10 SET amount=#{@val} WHERE word ='#{words[i]}'") end end else row = $dbase.get_first_row( "select amount from EZTop10 WHERE word='#{words}'") if(row==nil) $dbase.execute("insert into EZTop10 (word,amount) values('#{words}',1)") else @val = row[0] + 1 $dbase.execute("UPDATE EZTop10 SET amount=#{@val} WHERE word ='#{words}'") end end end |
#getTOP10 ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/EZTOP10.rb', line 10 def getTOP10 row = $dbase.execute( "select word from EZTop10 order by amount DESC" ) @top10 = Array.new for i in 0..9 if(row[i]==nil) return @top10 else @top10[i] = row[i] end end return @top10 end |