key-db 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/keydb.rb +38 -0
  2. metadata +4 -4
  3. data/lib/hashkeydb.rb +0 -38
data/lib/keydb.rb ADDED
@@ -0,0 +1,38 @@
1
+ class KeyDB
2
+ def initialize filename
3
+ @filename = filename.split(".")
4
+ @filename = "#{@filename[0]}.db"
5
+ unless Dir.entries('.').detect {|f| f.match "#{@filename}"}
6
+ @db_file = File.new(@filename, "w")
7
+ @db_file.close
8
+ end
9
+ end
10
+ def new_key keyname, value
11
+ @db_file = File.open(@filename, "a")
12
+ @to_write = (Marshal.dump("#{keyname}/#{value}"))
13
+ @db_file.write(@to_write)
14
+ @db_file.write("\n")
15
+ @db_file.close
16
+ end
17
+ def get_key keyname
18
+ File.open(@filename, "r").each_line do |line|
19
+ line = Marshal.load(line)
20
+ if line[keyname]
21
+ val = line.split("/")
22
+ puts val[1]
23
+ end
24
+ end
25
+ end
26
+ def access type
27
+ File.open(@filename).each_line do |line|
28
+ line = Marshal.load(line)
29
+ @keys_and_vals = line.split('/')
30
+ if type == "keys"
31
+ index = 0
32
+ elsif type == "vals"
33
+ index = 1
34
+ end
35
+ puts @keys_and_vals[index]
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: key-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,14 +11,14 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-05-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: A database acessible via keys, all bugs fixed, marshaling included. Renamed
15
- recall_key method to get_key
14
+ description: A database acessible via keys, bugs fixed, marshaling included. Renamed
15
+ HashKeyDB to KeyDB
16
16
  email: slmnwise@gmail.com
17
17
  executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - lib/hashkeydb.rb
21
+ - lib/keydb.rb
22
22
  homepage: http://rubygems.org/gems/key-db
23
23
  licenses: []
24
24
  post_install_message:
data/lib/hashkeydb.rb DELETED
@@ -1,38 +0,0 @@
1
- class HashKeyDB
2
- def initialize filename
3
- @filename = filename.split(".")
4
- @filename = "#{@filename[0]}.db"
5
- unless Dir.entries('.').detect {|f| f.match "#{@filename}"}
6
- @db_file = File.new(@filename, "w")
7
- @db_file.close
8
- end
9
- end
10
- def new_key keyname, value
11
- @db_file = File.open(@filename, "a")
12
- @to_write = (Marshal.dump("#{keyname}/#{value}"))
13
- @db_file.write(@to_write)
14
- @db_file.write("\n")
15
- @db_file.close
16
- end
17
- def get_key keyname
18
- File.open(@filename, "r").each_line do |line|
19
- line = Marshal.load(line)
20
- if line[keyname]
21
- val = line.split("/")
22
- puts val[1]
23
- end
24
- end
25
- end
26
- def access type
27
- File.open(@filename).each_line do |line|
28
- line = Marshal.load(line)
29
- @keys_and_vals = line.split('/')
30
- if type == "keys"
31
- index = 0
32
- elsif type == "vals"
33
- index = 1
34
- end
35
- puts @keys_and_vals[index]
36
- end
37
- end
38
- end