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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2f5fdd69f3165834247157f2302e117c2c451fbfbeab2e7e805f2ccbe39eaa0
4
- data.tar.gz: 0c987705aad4913b627290b4c0c280e191eea4cc2c917de9f623ccb65e6253f6
3
+ metadata.gz: 057c1560f457ceefbd403a6af21b064c460537c0e736a10e0b7e4b48b01af89c
4
+ data.tar.gz: d838e4d19a54b2a27dd5709bc6957720ddbf42303579ebbae44439ae4b8c57cf
5
5
  SHA512:
6
- metadata.gz: c698c0b59ee1c39b727b81a2d189f31688923749d6f00d73c7d9d6f57682226b7cb725e9adc5a4ebe5a9ed38a997c4bcecf4f7f638a777840dfdc33d32aa90cc
7
- data.tar.gz: 44b2ef590e95d5676e7e86c8d606f0e962a2274bb49a43bec939acea1855e99be7140a758d481a04e8619acc5b246ffc75f56bc40a9050e45d5c117ab98fef79
6
+ metadata.gz: a34432dd363f086dbd61472708b954a1a2c51335f7debdd160b7bce0f8316b6810437d10cc6fb7c342be9a58255f3ead7d91bebb02613456b177854cad224c79
7
+ data.tar.gz: a06df097ab1c3261012625ce5a33478f11fa2efcd0ead949ed43f927980c449082818737337cb349d4d283263274b62fb6b8adac4f75189262f8556b939c52f8
@@ -4,6 +4,7 @@ require "yaml"
4
4
  require "zip"
5
5
  require "zip/zip"
6
6
  require "rest_client"
7
+ require "datapackage"
7
8
 
8
9
  require "hsds_transformer/version"
9
10
  require "hsds_transformer/file_paths"
@@ -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", datapackage_json_path)
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, :output_data_path, :datapackage_json_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
- @datapackage_json_path = File.join(ENV["ROOT_PATH"], "lib/datapackage/datapackage.json")
39
+ @default_datapackage_json_path = File.join(ENV["ROOT_PATH"], "lib/datapackage/datapackage.json")
38
40
  end
39
41
  end
40
42
  end
@@ -1,3 +1,3 @@
1
1
  module HsdsTransformer
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  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.5
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: 1.3.0
120
- - - ">="
139
+ version: 2.0.0
140
+ - - "<"
121
141
  - !ruby/object:Gem::Version
122
- version: 1.3.0
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: 1.3.0
130
- - - ">="
149
+ version: 2.0.0
150
+ - - "<"
131
151
  - !ruby/object:Gem::Version
132
- version: 1.3.0
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: []