Module: Bolognese::Writers::JatsWriter
- Included in:
- Metadata
- Defined in:
- lib/bolognese/writers/jats_writer.rb
Instance Method Summary collapse
- #date ⇒ Object
- #insert_authors(xml) ⇒ Object
- #insert_citation(xml) ⇒ Object
- #insert_citation_title(xml) ⇒ Object
- #insert_contributor(xml, person) ⇒ Object
- #insert_editors(xml) ⇒ Object
- #insert_fpage(xml) ⇒ Object
- #insert_issue(xml) ⇒ Object
- #insert_lpage(xml) ⇒ Object
- #insert_pub_id(xml) ⇒ Object
- #insert_publication_date(xml) ⇒ Object
- #insert_publisher_name(xml) ⇒ Object
- #insert_source(xml) ⇒ Object
- #insert_version(xml) ⇒ Object
- #insert_volume(xml) ⇒ Object
- #is_article? ⇒ Boolean
- #is_chapter? ⇒ Boolean
- #is_data? ⇒ Boolean
- #jats ⇒ Object
- #publication_type ⇒ Object
Instance Method Details
#date ⇒ Object
121 122 123 |
# File 'lib/bolognese/writers/jats_writer.rb', line 121 def date get_date_parts(date_published) end |
#insert_authors(xml) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bolognese/writers/jats_writer.rb', line 39 def (xml) if .present? xml.send("person-group", "person-group-type" => "author") do Array.wrap().each do |creator| xml.name do insert_contributor(xml, creator) end end end end end |
#insert_citation(xml) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bolognese/writers/jats_writer.rb', line 12 def insert_citation(xml) (xml) insert_editors(xml) insert_citation_title(xml) if is_article? || is_data? || is_chapter? insert_source(xml) insert_publisher_name(xml) if publisher.present? && !is_data? insert_publication_date(xml) insert_volume(xml) if volume.present? insert_issue(xml) if issue.present? insert_fpage(xml) if first_page.present? insert_lpage(xml) if last_page.present? insert_version(xml) if version.present? insert_pub_id(xml) end |
#insert_citation_title(xml) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/bolognese/writers/jats_writer.rb', line 68 def insert_citation_title(xml) case publication_type.fetch('publication-type', nil) when "data" then xml.send("data-title", title) when "journal" then xml.send("article-title", title) when "chapter" then xml.send("chapter-title", title) end end |
#insert_contributor(xml, person) ⇒ Object
63 64 65 66 |
# File 'lib/bolognese/writers/jats_writer.rb', line 63 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
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bolognese/writers/jats_writer.rb', line 51 def insert_editors(xml) if editor.present? xml.send("person-group", "person-group-type" => "editor") do Array.wrap(editor).each do |creator| xml.name do insert_contributor(xml, creator) end end end end end |
#insert_fpage(xml) ⇒ Object
104 105 106 |
# File 'lib/bolognese/writers/jats_writer.rb', line 104 def insert_fpage(xml) xml.fpage(first_page) end |
#insert_issue(xml) ⇒ Object
100 101 102 |
# File 'lib/bolognese/writers/jats_writer.rb', line 100 def insert_issue(xml) xml.issue(issue) end |
#insert_lpage(xml) ⇒ Object
108 109 110 |
# File 'lib/bolognese/writers/jats_writer.rb', line 108 def insert_lpage(xml) xml.lpage(last_page) end |
#insert_pub_id(xml) ⇒ Object
116 117 118 119 |
# File 'lib/bolognese/writers/jats_writer.rb', line 116 def insert_pub_id(xml) return nil unless doi.present? xml.send("pub-id", doi, "pub-id-type" => "doi") end |
#insert_publication_date(xml) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/bolognese/writers/jats_writer.rb', line 88 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
84 85 86 |
# File 'lib/bolognese/writers/jats_writer.rb', line 84 def insert_publisher_name(xml) xml.send("publisher-name", publisher) end |
#insert_source(xml) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/bolognese/writers/jats_writer.rb', line 76 def insert_source(xml) if is_article? || is_data? || is_chapter? xml.source(container_title || publisher) else xml.source(title) end end |
#insert_version(xml) ⇒ Object
112 113 114 |
# File 'lib/bolognese/writers/jats_writer.rb', line 112 def insert_version(xml) xml.version(version) end |
#insert_volume(xml) ⇒ Object
96 97 98 |
# File 'lib/bolognese/writers/jats_writer.rb', line 96 def insert_volume(xml) xml.volume(volume) end |
#is_article? ⇒ Boolean
27 28 29 |
# File 'lib/bolognese/writers/jats_writer.rb', line 27 def is_article? publication_type.fetch('publication-type', nil) == "journal" end |
#is_chapter? ⇒ Boolean
35 36 37 |
# File 'lib/bolognese/writers/jats_writer.rb', line 35 def is_chapter? publication_type.fetch('publication-type', nil) == "chapter" end |
#is_data? ⇒ Boolean
31 32 33 |
# File 'lib/bolognese/writers/jats_writer.rb', line 31 def is_data? publication_type.fetch('publication-type', nil) == "data" end |
#jats ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/bolognese/writers/jats_writer.rb', line 4 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_type ⇒ Object
125 126 127 |
# File 'lib/bolognese/writers/jats_writer.rb', line 125 def publication_type { 'publication-type' => Bolognese::Utils::CR_TO_JATS_TRANSLATIONS[additional_type] || Bolognese::Utils::SO_TO_JATS_TRANSLATIONS[type] }.compact end |