csv_to_object 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -2
- data/lib/csv_to_object/version.rb +1 -1
- data/lib/csv_to_object.rb +6 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# CsvToObject
|
2
2
|
|
3
|
-
Given a CSV file, will return a collection of objects. The csv file name must match the name of an object the gem can instantiate. The first line of the csv file must define attribute names. The following lines contain the data that will be assigned to those attributes
|
3
|
+
Given the path to a CSV file, will return a collection of objects. The csv file name must match the name of an object the gem can instantiate. The first line of the csv file must define attribute names. The following lines contain the data that will be assigned to those attributes
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -24,7 +24,7 @@ Given a file person.csv with the contents
|
|
24
24
|
`0,Lindsey,Austino`
|
25
25
|
`1,Dodie,Egnor`
|
26
26
|
|
27
|
-
`CsvToObject::CsvToObject.new(
|
27
|
+
`CsvToObject::CsvToObject.new('[path to person.csv]').to_objects` will return
|
28
28
|
|
29
29
|
`[#<Person:0x000001021a8148 @id=0, @first_name="Lindsey", @last_name="Austino">, #<Person:0x000001021a8030 @id=1, @first_name="Dodie", @last_name="Egnor">`]
|
30
30
|
|
data/lib/csv_to_object.rb
CHANGED
@@ -4,10 +4,16 @@ require 'CSV'
|
|
4
4
|
module CsvToObject
|
5
5
|
class CsvToObject
|
6
6
|
|
7
|
+
# Requires the path to the csv file.
|
7
8
|
def initialize(input_path)
|
8
9
|
@input = File.open(input_path)
|
9
10
|
end
|
10
11
|
|
12
|
+
# Converts the data lines of the csv file to objects.
|
13
|
+
# Objects have the class of the name of the csv file.
|
14
|
+
# The first line of the csv file defines the attribute names for the data lines.
|
15
|
+
#
|
16
|
+
# person.csv => [person objects]
|
11
17
|
def to_objects
|
12
18
|
objects = []
|
13
19
|
CSV.table(@input).each do |row|
|
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: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2168815940 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2168815940
|
25
25
|
description: Takes a CSV file and returns a a collection of objects generated by that
|
26
26
|
CSV file.
|
27
27
|
email:
|