datacatalog-importer 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/datacatalog-importer.gemspec +1 -1
- data/lib/utility.rb +10 -7
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/lib/utility.rb
CHANGED
@@ -28,14 +28,16 @@ module DataCatalog
|
|
28
28
|
|
29
29
|
def self.headers
|
30
30
|
{
|
31
|
-
"UserAgent" => "National Data Catalog Importer/0.1.
|
31
|
+
"UserAgent" => "National Data Catalog Importer/0.1.5",
|
32
32
|
}
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
# { :headers => true } is a common option
|
36
|
+
def self.parse_csv_from_file(filename, options={})
|
37
|
+
extra_header_rows = options.delete(:extra_header_rows) || 0
|
36
38
|
File.open(filename) do |f|
|
37
39
|
extra_header_rows.times { f.gets } # ignore these rows
|
38
|
-
FasterCSV.parse(f)
|
40
|
+
FasterCSV.parse(f, options)
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -46,11 +48,12 @@ module DataCatalog
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def self.parse_csv_from_file_or_uri(uri, file, options={})
|
49
|
-
|
51
|
+
force_fetch = options.delete(:force_fetch) || false
|
52
|
+
if force_fetch || !File.exist?(file)
|
50
53
|
document = fetch(uri)
|
51
54
|
File.open(file, "w") { |f| f.write(document) }
|
52
55
|
end
|
53
|
-
parse_csv_from_file(file, options
|
56
|
+
parse_csv_from_file(file, options)
|
54
57
|
end
|
55
58
|
|
56
59
|
def self.parse_html_from_file_or_uri(uri, file, options={})
|
@@ -61,11 +64,11 @@ module DataCatalog
|
|
61
64
|
parse_html_from_file(file) # Why always parse the file? See Note 001, below.
|
62
65
|
end
|
63
66
|
|
64
|
-
def self.parse_csv_from_uri(uri)
|
67
|
+
def self.parse_csv_from_uri(uri, options={})
|
65
68
|
puts "Fetching #{uri}..."
|
66
69
|
data = open(uri, headers)
|
67
70
|
puts data.inspect
|
68
|
-
FasterCSV.parse(data)
|
71
|
+
FasterCSV.parse(data, options)
|
69
72
|
end
|
70
73
|
|
71
74
|
def self.parse_html_from_uri(uri)
|