csv_madness 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ Jeweler::Tasks.new do |gem|
25
25
  gem.email = "keeputahweird@gmail.com"
26
26
  gem.authors = ["Bryce Anderson"]
27
27
  # dependencies defined in Gemfile
28
- gem.files = [ "./lib/csv_madness/csv_recipe.rb",
28
+ gem.files = [ "./lib/csv_madness/data_accessor_module.rb",
29
29
  "./lib/csv_madness/record.rb",
30
30
  "./lib/csv_madness/sheet.rb",
31
31
  "./lib/csv_madness.rb",
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -0,0 +1,44 @@
1
+ class DataAccessorModule < Module
2
+ def initialize( mapping )
3
+ @column_accessors = []
4
+ remap_accessors( mapping )
5
+ end
6
+
7
+ def install_column_accessors( column, index )
8
+ @column_accessors << column
9
+ eval <<-EOF
10
+ self.send( :define_method, :#{column} ) do
11
+ self.csv_data[#{index}]
12
+ end
13
+
14
+ self.send( :define_method, :#{column}= ) do |val|
15
+ self.csv_data[#{index}] = val
16
+ end
17
+ EOF
18
+ end
19
+
20
+ def remove_column_accessors( column )
21
+ self.send( :remove_method, column )
22
+ self.send( :remove_method, :"#{column}=" )
23
+ end
24
+
25
+ def remove_all_column_accessors
26
+ @column_accessors ||= []
27
+
28
+ for sym in @column_accessors
29
+ remove_column_accessors( sym )
30
+ end
31
+
32
+ @column_accessors = []
33
+ end
34
+
35
+ def remap_accessors( mapping )
36
+ remove_all_column_accessors
37
+
38
+ @mapping = mapping
39
+
40
+ for column, index in @mapping
41
+ install_column_accessors( column, index )
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_madness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -105,6 +105,7 @@ files:
105
105
  - ./Rakefile
106
106
  - ./VERSION
107
107
  - ./lib/csv_madness.rb
108
+ - ./lib/csv_madness/data_accessor_module.rb
108
109
  - ./lib/csv_madness/record.rb
109
110
  - ./lib/csv_madness/sheet.rb
110
111
  - ./test/csv/simple.csv
@@ -127,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
128
  version: '0'
128
129
  segments:
129
130
  - 0
130
- hash: 279847321864815987
131
+ hash: 2889880782640461400
131
132
  required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  none: false
133
134
  requirements: