hsds_transformer 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hsds_transformer.rb +1 -0
- data/lib/hsds_transformer/base_transformer.rb +29 -2
- data/lib/hsds_transformer/file_paths.rb +4 -2
- data/lib/hsds_transformer/version.rb +1 -1
- metadata +47 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 057c1560f457ceefbd403a6af21b064c460537c0e736a10e0b7e4b48b01af89c
|
4
|
+
data.tar.gz: d838e4d19a54b2a27dd5709bc6957720ddbf42303579ebbae44439ae4b8c57cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a34432dd363f086dbd61472708b954a1a2c51335f7debdd160b7bce0f8316b6810437d10cc6fb7c342be9a58255f3ead7d91bebb02613456b177854cad224c79
|
7
|
+
data.tar.gz: a06df097ab1c3261012625ce5a33478f11fa2efcd0ead949ed43f927980c449082818737337cb349d4d283263274b62fb6b8adac4f75189262f8556b939c52f8
|
data/lib/hsds_transformer.rb
CHANGED
@@ -138,17 +138,44 @@ module HsdsTransformer
|
|
138
138
|
path_var = instance_variable_get "@output_#{model}_path"
|
139
139
|
write_csv path_var, headers(collection_ivar(model).first, model), collection_ivar(model)
|
140
140
|
end
|
141
|
+
write_datapackage_json
|
142
|
+
end
|
143
|
+
|
144
|
+
def write_datapackage_json
|
145
|
+
package = DataPackage::Package.new
|
146
|
+
|
147
|
+
# Is the output path in the file tree of the current directory? If so, we can work with it; if not, we can't.
|
148
|
+
# Due to "safe" file path requirements in the datapackage-rb library
|
149
|
+
path_chunks = output_datapackage_path.split(Dir.pwd)
|
150
|
+
if path_chunks[0] == ""
|
151
|
+
base_dir, remaining_path = parse_path(path_chunks)
|
152
|
+
descriptor = package.infer(directory: "#{remaining_path}/data", base_path: base_dir)
|
153
|
+
content_to_write = descriptor.to_json
|
154
|
+
else
|
155
|
+
content_to_write = File.read(default_datapackage_json_path)
|
156
|
+
end
|
157
|
+
File.open(output_datapackage_file_path, "wb") { |f| f.write(content_to_write) }
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns for example: ['tmp', 'input/data']
|
161
|
+
def parse_path(path_chunks)
|
162
|
+
path = path_chunks[1]
|
163
|
+
subpath_chunks = path.split("/")
|
164
|
+
base_dir = subpath_chunks[1]
|
165
|
+
remaining_path = subpath_chunks[2..-1].join("/")
|
166
|
+
[base_dir, remaining_path]
|
141
167
|
end
|
142
168
|
|
143
169
|
def zip_output
|
144
|
-
input_data_files = Dir.glob(File.join(output_data_path,
|
170
|
+
input_data_files = Dir.glob(File.join(output_data_path, "**/*"))
|
145
171
|
|
146
172
|
|
147
173
|
File.delete(zipfile_name) if File.exists?(zipfile_name)
|
148
174
|
|
149
175
|
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
176
|
+
|
150
177
|
# Add databpackage.json
|
151
|
-
zipfile.add("datapackage.json",
|
178
|
+
zipfile.add("datapackage.json", output_datapackage_file_path)
|
152
179
|
|
153
180
|
# Add data files
|
154
181
|
input_data_files.each do |file_path|
|
@@ -3,7 +3,8 @@ module HsdsTransformer
|
|
3
3
|
DEFAULT_OUTPUT_PATH = "#{ENV["ROOT_PATH"]}/tmp"
|
4
4
|
DEFAULT_INPUT_PATH = "#{ENV["ROOT_PATH"]}/"
|
5
5
|
|
6
|
-
attr_reader :input_path, :output_path, :output_datapackage_path, :
|
6
|
+
attr_reader :input_path, :output_path, :output_datapackage_path, :output_datapackage_file_path,
|
7
|
+
:output_data_path, :default_datapackage_json_path,
|
7
8
|
:zipfile_name, :output_organizations_path, :output_locations_path, :output_services_path,
|
8
9
|
:output_phones_path, :output_physical_addresses_path, :output_postal_addresses_path,
|
9
10
|
:output_services_at_locations_path, :output_eligibilities_path, :output_contacts_path,
|
@@ -15,6 +16,7 @@ module HsdsTransformer
|
|
15
16
|
@input_path = args[:input_path] || DEFAULT_INPUT_PATH
|
16
17
|
@output_path = args[:output_path] || DEFAULT_OUTPUT_PATH
|
17
18
|
@output_datapackage_path = File.join(output_path, "datapackage")
|
19
|
+
@output_datapackage_file_path = File.join(output_path, "datapackage/datapackage.json")
|
18
20
|
@output_data_path = File.join(output_datapackage_path, "data")
|
19
21
|
@zipfile_name = File.join(output_path, "datapackage.zip")
|
20
22
|
|
@@ -34,7 +36,7 @@ module HsdsTransformer
|
|
34
36
|
@output_regular_schedules_path = output_data_path + "/regular_schedules.csv"
|
35
37
|
@output_service_areas_path = output_data_path + "/service_areas.csv"
|
36
38
|
|
37
|
-
@
|
39
|
+
@default_datapackage_json_path = File.join(ENV["ROOT_PATH"], "lib/datapackage/datapackage.json")
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hsds_transformer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shelby Switzer
|
@@ -90,6 +90,26 @@ dependencies:
|
|
90
90
|
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: 1.1.0
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: pry
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 0.12.2
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.12.2
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.12.2
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 0.12.2
|
93
113
|
- !ruby/object:Gem::Dependency
|
94
114
|
name: unf_ext
|
95
115
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,20 +136,20 @@ dependencies:
|
|
116
136
|
requirements:
|
117
137
|
- - "~>"
|
118
138
|
- !ruby/object:Gem::Version
|
119
|
-
version:
|
120
|
-
- - "
|
139
|
+
version: 2.0.0
|
140
|
+
- - "<"
|
121
141
|
- !ruby/object:Gem::Version
|
122
|
-
version: 1.
|
142
|
+
version: 2.1.0
|
123
143
|
type: :runtime
|
124
144
|
prerelease: false
|
125
145
|
version_requirements: !ruby/object:Gem::Requirement
|
126
146
|
requirements:
|
127
147
|
- - "~>"
|
128
148
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
130
|
-
- - "
|
149
|
+
version: 2.0.0
|
150
|
+
- - "<"
|
131
151
|
- !ruby/object:Gem::Version
|
132
|
-
version: 1.
|
152
|
+
version: 2.1.0
|
133
153
|
- !ruby/object:Gem::Dependency
|
134
154
|
name: zip-zip
|
135
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,6 +210,26 @@ dependencies:
|
|
190
210
|
- - ">="
|
191
211
|
- !ruby/object:Gem::Version
|
192
212
|
version: 2.0.2
|
213
|
+
- !ruby/object:Gem::Dependency
|
214
|
+
name: datapackage
|
215
|
+
requirement: !ruby/object:Gem::Requirement
|
216
|
+
requirements:
|
217
|
+
- - "~>"
|
218
|
+
- !ruby/object:Gem::Version
|
219
|
+
version: 1.1.1
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 1.1.1
|
223
|
+
type: :runtime
|
224
|
+
prerelease: false
|
225
|
+
version_requirements: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: 1.1.1
|
230
|
+
- - ">="
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
version: 1.1.1
|
193
233
|
description: Gem for transforming data files into HSDS formatted datapackage
|
194
234
|
email: info@openreferral.org
|
195
235
|
executables: []
|