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 CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{datacatalog-importer}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David James"]
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.4",
31
+ "UserAgent" => "National Data Catalog Importer/0.1.5",
32
32
  }
33
33
  end
34
34
 
35
- def self.parse_csv_from_file(filename, extra_header_rows=0)
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
- if options[:force_fetch] || !File.exist?(file)
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[:extra_header_rows] || 0)
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datacatalog-importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David James