Class: DwcaHunter::ResourcePaleoBioDb

Inherits:
Resource
  • Object
show all
Defined in:
lib/dwca_hunter/resources/paleobiodb.rb

Constant Summary collapse

OCCURANCE_URL =
"http://paleobiodb.org/data1.2/occs/list.txt?" \
"datainfo&rowcount&base_name=Life&taxon_reso=species&" \
"idqual=certain&show=ecospace,loc,paleoloc,acconly"
TAXA_URL =
"http://paleobiodb.org/data1.2/taxa/list.txt?datainfo&" \
"rowcount&base_name=Life&variant=all&" \
"show=attr,common,app,parent,ecospace,ref,refattr,entname"
REFS_URL =
"http://paleobiodb.org/data1.2/taxa/refs.txt?datainfo&" \
"rowcount&base_name=Life&select=taxonomy"
TAXA_REFS_URL =
"http://paleobiodb.org/data1.2/taxa/byref.txt?datainfo&" \
"rowcount&base_name=Life&select=taxonomy"
URLS =
{
  occurences: OCCURANCE_URL,
  taxa: TAXA_URL,
  refs: REFS_URL,
  taxa_refs: TAXA_REFS_URL
}.freeze

Instance Attribute Summary

Attributes inherited from Resource

#abbr, #command, #download_path, #title, #url, #uuid

Instance Method Summary collapse

Methods inherited from Resource

gunzip, #needs_download?, #needs_unpack?, unzip

Constructor Details

#initialize(opts = {}) ⇒ ResourcePaleoBioDb

Returns a new instance of ResourcePaleoBioDb.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dwca_hunter/resources/paleobiodb.rb', line 23

def initialize(opts = {})
  # opts = {download: false}
  @command = "paleodb"
  @title = "The Paleobiology Database"
  @UUID =  "fad9970e-c358-4e1b-8cc3-f9ad2582751f"
  @download_path = File.join(Dir.tmpdir,
                             "dwca_hunter",
                             "paleobiodb", "fake.csv")
  @synonyms = []
  @names = []
  @vernaculars = []
  @extensions = []
  @synonyms_hash = {}
  @vernaculars_hash = {}
  super(opts)
end

Instance Method Details

#downloadObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dwca_hunter/resources/paleobiodb.rb', line 40

def download
  puts "Downloading from original."
  URLS.each do |k, v|
    file_name = k.to_s + ".txt"
    f = File.open(File.join(@download_dir, file_name), "w:utf-8")
    puts "Getting #{k}"
    data = RestClient::Request.execute(method: :get, url: v, timeout: 600)
    f.write(data)
    f.close
  end
  remove_header_text
end

#make_dwcaObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/dwca_hunter/resources/paleobiodb.rb', line 55

def make_dwca
  DwcaHunter.logger_write(object_id, "Extracting data")
  harvester = PaleodbHarvester.new(@download_dir)
  harvester.taxa
  harvester.refs
  harvester.taxa_refs
  harvester.occurences
  @taxa_json = JSON.parse(File.read(
                            File.join(@download_dir, "json", "taxa.json")
                          ), symbolize_names: true)
  @name_id_json = JSON.parse(File.read(
                               File.join(@download_dir, "json", "name_id.json")
                             ), symbolize_names: true)
  get_names
  generate_dwca
end

#unpackObject



53
# File 'lib/dwca_hunter/resources/paleobiodb.rb', line 53

def unpack; end