Module: Commonmeta::Writers::JatsWriter

Included in:
MetadataUtils
Defined in:
lib/commonmeta/writers/jats_writer.rb

Instance Method Summary collapse

Instance Method Details

#dateObject



129
130
131
# File 'lib/commonmeta/writers/jats_writer.rb', line 129

def date
  get_date_parts(date['published'])
end

#insert_authors(xml) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/commonmeta/writers/jats_writer.rb', line 41

def insert_authors(xml)
  return unless creators.present?

  xml.send(:'person-group', 'person-group-type' => 'author') do
    Array.wrap(creators).each do |au|
      xml.name do
        insert_contributor(xml, au)
      end
    end
  end
end

#insert_citation(xml) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/commonmeta/writers/jats_writer.rb', line 14

def insert_citation(xml)
  insert_authors(xml)
  insert_editors(xml)
  insert_citation_title(xml) if is_article? || is_data? || is_chapter?
  insert_source(xml)
  insert_publisher_name(xml) if publisher['name'].present? && !is_data?
  insert_publication_date(xml)
  insert_volume(xml) if container.to_h['volume'].present?
  insert_issue(xml) if container.to_h['issue'].present?
  insert_fpage(xml) if container.to_h['firstPage'].present?
  insert_lpage(xml) if container.to_h['lastPage'].present?
  insert_version(xml) if version.present?
  insert_pub_id(xml)
end

#insert_citation_title(xml) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/commonmeta/writers/jats_writer.rb', line 70

def insert_citation_title(xml)
  case publication_type.fetch('publication-type', nil)
  when 'data' then xml.send(:'data-title',
                            parse_attributes(titles, content: 'title', first: true))
  when 'journal' then xml.send(:'article-title',
                               parse_attributes(titles, content: 'title', first: true))
  when 'chapter' then xml.send(:'chapter-title',
                               parse_attributes(titles, content: 'title', first: true))
  end
end

#insert_contributor(xml, person) ⇒ Object



65
66
67
68
# File 'lib/commonmeta/writers/jats_writer.rb', line 65

def insert_contributor(xml, person)
  xml.surname(person['familyName']) if person['familyName'].present?
  xml.send(:'given-names', person['givenName']) if person['givenName'].present?
end

#insert_editors(xml) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/commonmeta/writers/jats_writer.rb', line 53

def insert_editors(xml)
  return unless contributors.present?

  xml.send(:'person-group', 'person-group-type' => 'editor') do
    Array.wrap(contributors).each do |con|
      xml.name do
        insert_contributor(xml, con)
      end
    end
  end
end

#insert_fpage(xml) ⇒ Object



111
112
113
# File 'lib/commonmeta/writers/jats_writer.rb', line 111

def insert_fpage(xml)
  xml.fpage(container['firstPage'])
end

#insert_issue(xml) ⇒ Object



107
108
109
# File 'lib/commonmeta/writers/jats_writer.rb', line 107

def insert_issue(xml)
  xml.issue(container['issue'])
end

#insert_lpage(xml) ⇒ Object



115
116
117
# File 'lib/commonmeta/writers/jats_writer.rb', line 115

def insert_lpage(xml)
  xml.lpage(container['lastPage'])
end

#insert_pub_id(xml) ⇒ Object



123
124
125
126
127
# File 'lib/commonmeta/writers/jats_writer.rb', line 123

def insert_pub_id(xml)
  return nil unless doi_from_url(id).present?

  xml.send(:'pub-id', doi_from_url(id), 'pub-id-type' => 'doi')
end

#insert_publication_date(xml) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/commonmeta/writers/jats_writer.rb', line 95

def insert_publication_date(xml)
  year, month, day = get_date_parts(date['published']).to_h.fetch('date-parts', []).first

  xml.year(year, 'iso-8601-date' => date['published'])
  xml.month(month.to_s.rjust(2, '0')) if month.present?
  xml.day(day.to_s.rjust(2, '0')) if day.present?
end

#insert_publisher_name(xml) ⇒ Object



91
92
93
# File 'lib/commonmeta/writers/jats_writer.rb', line 91

def insert_publisher_name(xml)
  xml.send(:'publisher-name', publisher['name'])
end

#insert_source(xml) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/commonmeta/writers/jats_writer.rb', line 81

def insert_source(xml)
  if is_chapter?
    xml.source(publisher['name'])
  elsif is_article? || is_data?
    xml.source((container && container['title']) || publisher['name'])
  else
    xml.source(parse_attributes(titles, content: 'title', first: true))
  end
end

#insert_version(xml) ⇒ Object



119
120
121
# File 'lib/commonmeta/writers/jats_writer.rb', line 119

def insert_version(xml)
  xml.version(version)
end

#insert_volume(xml) ⇒ Object



103
104
105
# File 'lib/commonmeta/writers/jats_writer.rb', line 103

def insert_volume(xml)
  xml.volume(container['volume'])
end

#is_article?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/commonmeta/writers/jats_writer.rb', line 29

def is_article?
  publication_type.fetch('publication-type', nil) == 'journal'
end

#is_chapter?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/commonmeta/writers/jats_writer.rb', line 37

def is_chapter?
  publication_type.fetch('publication-type', nil) == 'chapter'
end

#is_data?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/commonmeta/writers/jats_writer.rb', line 33

def is_data?
  publication_type.fetch('publication-type', nil) == 'data'
end

#jatsObject



6
7
8
9
10
11
12
# File 'lib/commonmeta/writers/jats_writer.rb', line 6

def jats
  @jats ||= Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
    xml.send(:'element-citation', publication_type) do
      insert_citation(xml)
    end
  end.to_xml
end

#publication_typeObject



133
134
135
# File 'lib/commonmeta/writers/jats_writer.rb', line 133

def publication_type
  { 'publication-type' => Commonmeta::Utils::CM_TO_JATS_TRANSLATIONS.fetch(type, nil) }
end