Class: DarwinCore::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/dwc_archive/generator.rb,
lib/dwc_archive/generator_eml_xml.rb,
lib/dwc_archive/generator_meta_xml.rb

Overview

Creates csv files for core and extensions

Defined Under Namespace

Classes: EmlXml, MetaXml

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dwc_path, tmp_dir = DEFAULT_TMP_DIR) ⇒ Generator

Returns a new instance of Generator.



8
9
10
11
12
13
14
15
16
# File 'lib/dwc_archive/generator.rb', line 8

def initialize(dwc_path, tmp_dir = DEFAULT_TMP_DIR)
  @dwc_path = dwc_path
  @path = DarwinCore.random_path(tmp_dir)
  FileUtils.mkdir(@path)
  @meta_xml_data = { extensions: [] }
  @eml_xml_data = { id: nil, title: nil, authors: [], abstrac: nil,
                    citation: nil, url: nil }
  @write = 'w:utf-8'
end

Instance Attribute Details

#eml_xml_dataObject (readonly)

Returns the value of attribute eml_xml_data.



6
7
8
# File 'lib/dwc_archive/generator.rb', line 6

def eml_xml_data
  @eml_xml_data
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/dwc_archive/generator.rb', line 6

def path
  @path
end

Instance Method Details

#add_core(data, file_name, keep_headers = true) ⇒ Object



22
23
24
25
26
# File 'lib/dwc_archive/generator.rb', line 22

def add_core(data, file_name, keep_headers = true)
  opts = { type: 'core', data: data, file_name: file_name,
           keep_headers: keep_headers }
  prepare_csv_file(opts)
end

#add_eml_xml(data) ⇒ Object



40
41
42
43
44
# File 'lib/dwc_archive/generator.rb', line 40

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



28
29
30
31
32
33
# File 'lib/dwc_archive/generator.rb', line 28

def add_extension(data, file_name, keep_headers = true,
                  row_type = 'http://rs.tdwg.org/dwc/terms/Taxon')
  opts = { type: 'extension', data: data, file_name: file_name,
           keep_headers: keep_headers, row_type: row_type }
  prepare_csv_file(opts)
end

#add_meta_xmlObject



35
36
37
38
# File 'lib/dwc_archive/generator.rb', line 35

def add_meta_xml
  meta = DarwinCore::Generator::MetaXml.new(@meta_xml_data, @path)
  meta.create
end

#cleanObject



18
19
20
# File 'lib/dwc_archive/generator.rb', line 18

def clean
  DarwinCore.clean(@path)
end

#filesObject



46
47
48
# File 'lib/dwc_archive/generator.rb', line 46

def files
  DarwinCore.files(@path)
end

#packObject



50
51
52
53
# File 'lib/dwc_archive/generator.rb', line 50

def pack
  a = "cd #{@path}; tar -zcf #{@dwc_path} *"
  system(a)
end