csv_to_object 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/csv_to_object.rb +8 -1
- data/lib/csv_to_object/version.rb +1 -1
- data/spec/csv_to_object_spec.rb +22 -0
- data/test/csv/multi_word_class.csv +3 -0
- metadata +5 -3
data/lib/csv_to_object.rb
CHANGED
@@ -36,8 +36,15 @@ module CsvToObject
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def object_to_create()
|
39
|
-
class_name = File.basename(@input_path).gsub('.csv','').capitalize
|
40
39
|
@object = Object::const_get(class_name)
|
41
40
|
end
|
41
|
+
|
42
|
+
def class_name
|
43
|
+
bare_file_name.split('_').map { |word| word.capitalize}.join
|
44
|
+
end
|
45
|
+
|
46
|
+
def bare_file_name
|
47
|
+
File.basename(@input_path).gsub('.csv','')
|
48
|
+
end
|
42
49
|
end
|
43
50
|
end
|
data/spec/csv_to_object_spec.rb
CHANGED
@@ -8,6 +8,16 @@ class Person
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
class MultiWordClass
|
12
|
+
attr_reader :id, :foo
|
13
|
+
|
14
|
+
def initialize(args={})
|
15
|
+
@id = args["id"]
|
16
|
+
@foo = args["foo"]
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
11
21
|
describe CsvToObject do
|
12
22
|
before(:each) do
|
13
23
|
@test_csv_path = 'test/csv/person.csv'
|
@@ -27,6 +37,18 @@ describe CsvToObject do
|
|
27
37
|
@c2o.to_objects.first.class.to_s.should == File.basename(@source_file.path).gsub('.csv','').capitalize
|
28
38
|
end
|
29
39
|
|
40
|
+
context "given a multi_word file name in snake case" do
|
41
|
+
before(:each) do
|
42
|
+
@snake_case_file = 'test/csv/multi_word_class.csv'
|
43
|
+
end
|
44
|
+
it "it creates MultiWord objects" do
|
45
|
+
objects = CsvToObject::CsvToObject.new(@snake_case_file).to_objects
|
46
|
+
objects.each do |object|
|
47
|
+
object.should be_kind_of(MultiWordClass)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
30
52
|
it "returns as many objects as there are data lines in the csv file" do
|
31
53
|
@c2o.to_objects.count.should == @number_of_data_lines
|
32
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_to_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-10-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/csv_to_object/version.rb
|
49
49
|
- spec/csv_to_object_spec.rb
|
50
50
|
- spec/spec_helper.rb
|
51
|
+
- test/csv/multi_word_class.csv
|
51
52
|
- test/csv/person.csv
|
52
53
|
homepage: https://github.com/SeniorServiceAmerica/csv_to_object
|
53
54
|
licenses: []
|
@@ -69,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
70
|
version: '0'
|
70
71
|
requirements: []
|
71
72
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.8.
|
73
|
+
rubygems_version: 1.8.21
|
73
74
|
signing_key:
|
74
75
|
specification_version: 3
|
75
76
|
summary: Given the path to a CSV file, will return a collection of objects. The csv
|
@@ -79,4 +80,5 @@ summary: Given the path to a CSV file, will return a collection of objects. The
|
|
79
80
|
test_files:
|
80
81
|
- spec/csv_to_object_spec.rb
|
81
82
|
- spec/spec_helper.rb
|
83
|
+
- test/csv/multi_word_class.csv
|
82
84
|
- test/csv/person.csv
|