lib/dwc-archive/generator.rb in dwc-archive-0.9.6 vs lib/dwc-archive/generator.rb in dwc-archive-0.9.10

- old
+ new

@@ -6,11 +6,12 @@ def initialize(dwc_path, tmp_dir = DEFAULT_TMP_DIR) @dwc_path = dwc_path @path = File.join(tmp_dir, 'dwc_' + rand(10000000000).to_s) FileUtils.mkdir(@path) @meta_xml_data = {:extensions => []} - @eml_xml_data = {:id => nil, :title => nil, :authors => [], :abstract => nil, :citation => nil, :url => nil} + @eml_xml_data = {:id => nil, :title => nil, + :authors => [], :abstract => nil, :citation => nil, :url => nil} @write = 'w:utf-8' end #TODO refactor! def clean @@ -20,30 +21,39 @@ def add_core(data, file_name, keep_headers = true) c = CSV.open(File.join(@path,file_name), @write) header = data.shift fields = header.map do |f| f.strip! - raise DarwinCore::GeneratorError.new("No header in core data, or header fields are not urls") unless f.match(/^http:\/\//) - f.split("/")[-1] + err = 'No header in core data, or header fields are not urls' + raise DarwinCore::GeneratorError.new(err) unless f.match(/^http:\/\//) + f.split('/')[-1] end data.unshift(fields) if keep_headers ignore_header_lines = keep_headers ? 1 : 0 - @meta_xml_data[:core] = {:fields => header, :ignoreHeaderLines => ignore_header_lines, :location => file_name} + @meta_xml_data[:core] = { fields: header, + ignoreHeaderLines: ignore_header_lines, + location:file_name } data.each {|d| c << d} c.close end - def add_extension(data, file_name, keep_headers = true, row_type = "http://rs.tdwg.org/dwc/terms/Taxon") + def add_extension(data, file_name, + keep_headers = true, + row_type = 'http://rs.tdwg.org/dwc/terms/Taxon') c = CSV.open(File.join(@path,file_name), @write) header = data.shift fields = header.map do |f| f.strip! - raise DarwinCore::GeneratorError.new("No header in core data, or header fields are not urls") unless f.match(/^http:\/\//) - f.split("/")[-1] + err = 'No header in core data, or header fields are not urls' + raise DarwinCore::GeneratorError.new(err) unless f.match(/^http:\/\//) + f.split('/')[-1] end data.unshift(fields) if keep_headers ignore_header_lines = keep_headers ? 1 : 0 - @meta_xml_data[:extensions] << { :fields => header, :ignoreHeaderLines => ignore_header_lines, :location => file_name, :rowType => row_type } + @meta_xml_data[:extensions] << { fields: header, + ignoreHeaderLines: ignore_header_lines, + location: file_name, + rowType: row_type } data.each { |d| c << d } c.close end def add_meta_xml