Module: AnyStyle::Format::RIS
- Included in:
- Parser
- Defined in:
- lib/anystyle/format/ris.rb
Instance Method Summary collapse
- #add_authors(lines, authors) ⇒ Object
- #format_entry(entry) ⇒ Object
- #format_ris(dataset, **opts) ⇒ Object
-
#ris_type(type) ⇒ Object
Extended RIS type mapping.
- #unwrap(val) ⇒ Object
Instance Method Details
#add_authors(lines, authors) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/anystyle/format/ris.rb', line 55 def (lines, ) return unless .each do || name = if [:literal] [:literal] elsif [:family] || [:given] family = [:family] given = [:given]&.gsub('.', '') # Add space between adjacent uppercase initials (e.g., "HJ" => "H J") given = given.gsub(/(?<=\A|\s)([A-Z])(?=[A-Z])/, '\1 ') if given [family, given].compact.join(', ') else nil end lines << "AU - #{name}" if name end end |
#format_entry(entry) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/anystyle/format/ris.rb', line 8 def format_entry(entry) lines = [] type = ris_type(entry[:type]) lines << "TY - #{type}" (lines, entry[:author]) lines << "PY - #{unwrap(entry[:issued])}" if entry[:issued] lines << "TI - #{unwrap(entry[:title])}" if entry[:title] lines << "T2 - #{unwrap(entry[:'container-title'])}" if entry[:'container-title'] lines << "PB - #{unwrap(entry[:publisher])}" if entry[:publisher] lines << "SN - #{unwrap(entry[:ISBN] || entry[:ISSN])}" if entry[:ISBN] || entry[:ISSN] lines << "DO - #{unwrap(entry[:DOI])}" if entry[:DOI] lines << "UR - #{unwrap(entry[:URL])}" if entry[:URL] lines << "ET - #{unwrap(entry[:edition])}" if entry[:edition] lines << "CY - #{unwrap(entry[:'publisher-place'] || entry[:location])}" if entry[:'publisher-place'] || entry[:location] lines << "VL - #{unwrap(entry[:volume])}" if entry[:volume] lines << "IS - #{unwrap(entry[:issue])}" if entry[:issue] lines << "SP - #{unwrap(entry[:page].to_s.split('-')[0])}" if entry[:page] lines << "EP - #{unwrap(entry[:page].to_s.split('-')[1])}" if entry[:page]&.include?("-") lines << "ER -" lines.join("\n") end |
#format_ris(dataset, **opts) ⇒ Object
4 5 6 |
# File 'lib/anystyle/format/ris.rb', line 4 def format_ris(dataset, **opts) format_hash(dataset).map { |entry| format_entry(entry) }.join("\n\n") + "\n" end |
#ris_type(type) ⇒ Object
Extended RIS type mapping
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/anystyle/format/ris.rb', line 34 def ris_type(type) case type.to_s.downcase when 'book' then 'BOOK' # Book when 'chapter' then 'CHAP' # Book chapter when 'article-journal' then 'JOUR' # Journal article when 'magazine-article', 'magazine' then 'MGZN' # Magazine when 'newspaper-article', 'news' then 'NEWS' # Newspaper when 'conference-paper', 'proceedings-article' then 'CONF' # Conference when 'manuscript' then 'UNPB' # Unpublished when 'thesis' then 'THES' # Thesis/dissertation when 'webpage', 'electronic', 'online' then 'ELEC' # Electronic source when 'film' then 'MPCT' # Motion picture when 'report' then 'RPRT' # Technical report else 'GEN' # Generic fallback end end |
#unwrap(val) ⇒ Object
51 52 53 |
# File 'lib/anystyle/format/ris.rb', line 51 def unwrap(val) val.is_a?(Array) ? val.first : val end |