Class: DarwinCore::Generator
- Inherits:
-
Object
- Object
- DarwinCore::Generator
- Defined in:
- lib/dwc-archive/generator.rb,
lib/dwc-archive/generator_eml_xml.rb,
lib/dwc-archive/generator_meta_xml.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#eml_xml_data ⇒ Object
readonly
Returns the value of attribute eml_xml_data.
Instance Method Summary collapse
- #add_core(data, file_name, keep_headers = true) ⇒ Object
- #add_eml_xml(data) ⇒ Object
- #add_extension(data, file_name, keep_headers = true, row_type = 'http://rs.tdwg.org/dwc/terms/Taxon') ⇒ Object
- #add_meta_xml ⇒ Object
-
#clean ⇒ Object
TODO refactor!.
- #files ⇒ Object
-
#initialize(dwc_path, tmp_dir = DEFAULT_TMP_DIR) ⇒ Generator
constructor
TODO refactor – for now copying expander methods.
- #pack ⇒ Object
- #path ⇒ Object
Constructor Details
#initialize(dwc_path, tmp_dir = DEFAULT_TMP_DIR) ⇒ Generator
TODO refactor – for now copying expander methods
6 7 8 9 10 11 12 13 14 |
# File 'lib/dwc-archive/generator.rb', line 6 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} @write = 'w:utf-8' end |
Instance Attribute Details
#eml_xml_data ⇒ Object (readonly)
Returns the value of attribute eml_xml_data.
3 4 5 |
# File 'lib/dwc-archive/generator.rb', line 3 def eml_xml_data @eml_xml_data end |
Instance Method Details
#add_core(data, file_name, keep_headers = true) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dwc-archive/generator.rb', line 21 def add_core(data, file_name, keep_headers = true) c = CSV.open(File.join(@path,file_name), @write) header = data.shift fields = get_fields(header, 'core') 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 } data.each {|d| c << d} c.close end |
#add_eml_xml(data) ⇒ Object
55 56 57 58 59 |
# File 'lib/dwc-archive/generator.rb', line 55 def add_eml_xml(data) @eml_xml_data = data eml = DarwinCore::Generator::EmlXml.new(@eml_xml_data, @path) eml.create end |
#add_extension(data, file_name, keep_headers = true, row_type = 'http://rs.tdwg.org/dwc/terms/Taxon') ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dwc-archive/generator.rb', line 34 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 = get_fields(header, 'extension') 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 } data.each { |d| c << d } c.close end |
#add_meta_xml ⇒ Object
50 51 52 53 |
# File 'lib/dwc-archive/generator.rb', line 50 def = DarwinCore::Generator::MetaXml.new(@meta_xml_data, @path) .create end |
#clean ⇒ Object
TODO refactor!
17 18 19 |
# File 'lib/dwc-archive/generator.rb', line 17 def clean FileUtils.rm_rf(@path) if FileTest.exists?(@path) end |
#files ⇒ Object
65 66 67 68 |
# File 'lib/dwc-archive/generator.rb', line 65 def files return nil unless @path && FileTest.exists?(@path) Dir.entries(@path).select {|e| e !~ /[\.]{1,2}$/}.sort end |
#pack ⇒ Object
70 71 72 73 |
# File 'lib/dwc-archive/generator.rb', line 70 def pack a = "cd #{@path}; tar -zcf #{@dwc_path} *" system(a) end |
#path ⇒ Object
61 62 63 |
# File 'lib/dwc-archive/generator.rb', line 61 def path @path end |