31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/export/coldp/files/type_material.rb', line 31
def self.generate(otus, project_members, reference_csv = nil )
::CSV.generate(col_sep: "\t") do |csv|
csv << %w{
ID
nameID
citation
status
referenceID
locality
country
latitude
longitude
altitude
host
date
collector
institutionCode
catalogNumber
associatedSequences
sex
link
modified
modifiedBy
remarks
}
TypeMaterial.joins(:otus).where(otus: otus).eager_load(:collection_object).find_each do |tm|
co = tm.collection_object
sources = tm.sources.load
reference_ids = sources.collect{|a| a.id}
reference_id = reference_ids.first
csv << [
nil, tm.protonym_id, co.buffered_collecting_event, tm.type_type, reference_id, locality(co), co.collecting_event&.cached_level0_geographic_name, co.dwc_decimal_latitude, co.dwc_decimal_longitude, co.dwc_verbatim_elevation, nil, date(co), co.dwc_recorded_by, co.dwc_institution_code, co.dwc_catalog_number, nil, nil, nil, Export::Coldp.modified(tm[:updated_at]), Export::Coldp.modified_by(tm[:updated_by_id], project_members), nil ]
Export::Coldp::Files::Reference.add_reference_rows(sources, reference_csv, project_members) if reference_csv
end
end
end
|