EZTOP10 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/EZTOP10.rb +44 -0
  2. metadata +46 -0
data/lib/EZTOP10.rb ADDED
@@ -0,0 +1,44 @@
1
+ class EZTop10
2
+ require 'sqlite3'
3
+
4
+ def initialize(db)
5
+ $dbase= SQLite3::Database.new(db)
6
+ $dbase.execute("CREATE TABLE IF NOT EXISTS EZTop10(Id INTEGER PRIMARY KEY,
7
+ word VARCHAR Unique, amount INTEGER)")
8
+ end
9
+
10
+ def getTOP10
11
+ row = $dbase.execute( "select word from EZTop10 order by amount DESC" )
12
+ @top10 = Array.new
13
+ for i in 0..9
14
+ if(row[i]==nil)
15
+ return @top10
16
+ else
17
+ @top10[i] = row[i]
18
+ end
19
+ end
20
+ return @top10
21
+ end
22
+
23
+ def AddWords(words)
24
+ if(words.kind_of?(Array))
25
+ for i in 0..words.count-1
26
+ row = $dbase.get_first_row( "select amount from EZTop10 WHERE word='#{words[i]}'" )
27
+ if(row==nil)
28
+ $dbase.execute("insert into EZTop10 (word,amount) values('#{words[i]}',1)")
29
+ else
30
+ @val = row[0] + 1
31
+ $dbase.execute("UPDATE EZTop10 SET amount=#{@val} WHERE word ='#{words[i]}'")
32
+ end
33
+ end
34
+ else
35
+ row = $dbase.get_first_row( "select amount from EZTop10 WHERE word='#{words}'")
36
+ if(row==nil)
37
+ $dbase.execute("insert into EZTop10 (word,amount) values('#{words}',1)")
38
+ else
39
+ @val = row[0] + 1
40
+ $dbase.execute("UPDATE EZTop10 SET amount=#{@val} WHERE word ='#{words}'")
41
+ end
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: EZTOP10
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Darren Breen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Easy to use storing of words and retrieving commonly used words (top
15
+ 10). '
16
+ email: Darren.breen@ballyfad.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/EZTOP10.rb
22
+ homepage: http://www.ballyfad.com
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.24
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: EZTOP10 for quick adding and retrieving of words.
46
+ test_files: []