json_csv 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +18 -1
- data/lib/json_csv/csv_to_json.rb +1 -1
- data/lib/json_csv/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7dc36a6c25ffa37eae4a51c7d373763c3958eb10341f2659acbbf70c7f1f6cdf
|
4
|
+
data.tar.gz: de793cb71e127d0518cca18a1fc5c4f31d0d595df51f23abb0c79c02394b4435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abffea2f7c780e093a052e3d558526f5e1d93c4492a36de3e3d0a1d38eaa81be4f81ccd929352bd630b6a7db4e8b9141dc76d70a0f8a4986c5a6b1b9a1cf3316
|
7
|
+
data.tar.gz: d791b8465efb81add9160dc3f2d04a1772c3762c3cc88467d456820123153fb80df7c3f02dd2071ea8e4acd518e9fc87323b0d05cc77da927cd9bf871ddcdace
|
data/README.md
CHANGED
@@ -13,9 +13,26 @@ gem install json_csv
|
|
13
13
|
```ruby
|
14
14
|
require 'json_csv'
|
15
15
|
|
16
|
-
|
16
|
+
path_to_output_csv_file = '/path/to/file.csv'
|
17
|
+
|
18
|
+
# Write json-like hash objects to a csv file
|
19
|
+
|
20
|
+
JsonCsv.create_csv_for_json_records(path_to_output_csv_file) do |csv_builder|
|
21
|
+
digital_objects_for_batch_export(batch_export) do |digital_object|
|
22
|
+
csv_builder.add({...json-like hash...})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Read csv back into json-like hash objects
|
27
|
+
|
28
|
+
JsonCsv.csv_file_to_hierarchical_json_hash(csv_file.path) do |json_hash_for_row, csv_row_number|
|
29
|
+
puts "Row: #{csv_row_number}" # prints out 2 the first time, then 3, etc.
|
30
|
+
puts "Object: #{json_hash_for_row}" # prints out a hierarchical json object, created from the csv row
|
31
|
+
end
|
17
32
|
```
|
18
33
|
|
34
|
+
See specs for advanced usage.
|
35
|
+
|
19
36
|
### Running Tests (for developers):
|
20
37
|
|
21
38
|
Tests are great and we should run them. Here's how:
|
data/lib/json_csv/csv_to_json.rb
CHANGED
@@ -21,7 +21,7 @@ module JsonCsv
|
|
21
21
|
# because it only keeps one row in memory at a time.
|
22
22
|
# Sample usage: csv_file_to_hierarchical_json_hash(path_to_csv, field_casting_rules = {}, strip_value_whitespace = true) do |row_json_hash, row_number|
|
23
23
|
def csv_file_to_hierarchical_json_hash(path_to_csv, field_casting_rules = {}, strip_value_whitespace = true)
|
24
|
-
i =
|
24
|
+
i = 2 # start with row 2 because this corresponds to the SECOND row of 1-indexed CSV data (where headers are row 1)
|
25
25
|
CSV.foreach(path_to_csv, headers: true, header_converters: lambda { |header|
|
26
26
|
header.strip # remove leading and trailing header whitespace
|
27
27
|
}) do |row_data_hash|
|
data/lib/json_csv/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric O'Hanlon
|
@@ -114,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
|
118
|
-
rubygems_version: 2.6.14
|
117
|
+
rubygems_version: 3.0.8
|
119
118
|
signing_key:
|
120
119
|
specification_version: 4
|
121
120
|
summary: A library for converting json to csv...and back!
|