christiank-turntable 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/turntable.rb +12 -12
- metadata +2 -2
data/turntable.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
#
|
2
|
-
# turntable v0.4.
|
2
|
+
# turntable v0.4.4
|
3
3
|
# Christian Koch < ckoch002@student.ucr.edu >
|
4
4
|
#
|
5
5
|
# This is free software. You are permitted to modify, implement, and otherwise
|
6
6
|
# use this source code freely (as in beer and freedom).
|
7
7
|
#
|
8
|
-
|
8
|
+
|
9
9
|
class Turntable
|
10
10
|
|
11
|
-
@@version = '0.4.
|
11
|
+
@@version = '0.4.4'
|
12
12
|
|
13
13
|
# Creates a new Turntable object and database file.
|
14
14
|
# Requires a filename and at least one column name.
|
15
15
|
def initialize filename, *args
|
16
|
-
raise 'Turntable.new requires at least
|
16
|
+
raise 'Turntable.new requires a filename and at least one column name' if args.empty?
|
17
17
|
|
18
18
|
@columns = []
|
19
19
|
@table = []
|
20
|
-
@filename = filename
|
20
|
+
@filename = File.expand_path(filename)
|
21
21
|
|
22
22
|
args.each do |column|
|
23
23
|
@columns.push column
|
@@ -28,9 +28,9 @@ class Turntable
|
|
28
28
|
|
29
29
|
# Loads an external database file and returns the Turntable object.
|
30
30
|
def Turntable.load filename
|
31
|
-
raise "#{filename}: file does not exist" unless File.exists?(filename)
|
31
|
+
raise "\"#{filename}\": file does not exist" unless File.exists?(filename)
|
32
32
|
|
33
|
-
@filename = filename
|
33
|
+
@filename = File.expand_path(filename)
|
34
34
|
f = File.open @filename, 'r'
|
35
35
|
return Marshal.load(f)
|
36
36
|
f.close
|
@@ -62,7 +62,7 @@ class Turntable
|
|
62
62
|
raise 'delete() requires :id => some_value' unless hash.has_key?(:id)
|
63
63
|
|
64
64
|
before_table = @table.dup
|
65
|
-
|
65
|
+
|
66
66
|
# Delete the table for real here:
|
67
67
|
what_wasnt_deleted = @table.delete_if { |row| row[:id] == hash[:id] }
|
68
68
|
self.save_to @filename
|
@@ -73,7 +73,7 @@ class Turntable
|
|
73
73
|
|
74
74
|
# Eliminates an entire column.
|
75
75
|
def drop_column column_name
|
76
|
-
@columns.delete_if { |column| column == column_name}
|
76
|
+
@columns.delete_if { |column| column == column_name }
|
77
77
|
@table.each { |row| row.delete column_name }
|
78
78
|
end
|
79
79
|
|
@@ -179,9 +179,9 @@ class Turntable
|
|
179
179
|
f.close
|
180
180
|
end
|
181
181
|
end
|
182
|
-
|
182
|
+
|
183
183
|
class Array
|
184
|
-
|
184
|
+
|
185
185
|
# Rearranges an array of hashes according to a specified column name.
|
186
186
|
# TODO: how to check for @columns, even though it's a Turntable variable?
|
187
187
|
def order_by column_name
|
@@ -206,7 +206,7 @@ class Array
|
|
206
206
|
column[0] = column[0].to_sym
|
207
207
|
this_column_hash[ column[0] ] = column[1]
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
this_row_hash.update this_column_hash
|
211
211
|
end
|
212
212
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: christiank-turntable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Koch
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-31 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|