class SiSU_AO_Appendices::Bibliography
Public Class Methods
new(md,data)
click to toggle source
# File lib/sisu/ao_appendices.rb, line 110 def initialize(md,data) @md,@data=md,data end
Public Instance Methods
biblio_extraction()
click to toggle source
# File lib/sisu/ao_appendices.rb, line 330 def biblio_extraction bibliography=[] biblioflag=false code_flag=false flag_code_curly=:not_code_curly flag_code_tics=:not_code_tics @data=@data.select do |t_o| if t_o =~/^code\{/ flag_code_curly=:code_curly elsif t_o =~/^\}code/ flag_code_curly=:not_code_curly elsif t_o =~/^``` code/ flag_code_tics=:code_tics elsif flag_code_tics ==:code_tics \ and t_o =~/^```/ flag_code_tics=:not_code_tics end code_flag=if flag_code_curly==:code_curly \ or flag_code_tics==:code_tics true else false end unless code_flag if @md.flag_auto_biblio if t_o =~/^1~!biblio(?:graphy)?/ biblioflag = true t_o elsif t_o =~/^:?[B-D1]~/ biblioflag = false t_o elsif biblioflag if t_o !~/\A%+ / bibliography << citation_in_prepared_bibliography(t_o).citation_metadata next else t_o end else t_o end elsif @md.flag_biblio if t_o =~/^1~!biblio(?:graphy)?/ biblioflag = true next elsif t_o =~/^:?[B-D]~/ next elsif t_o =~/^:?[B-D1]~/ biblioflag = false t_o elsif biblioflag if t_o !~/\A%+ / bibliography << t_o next else t_o end else t_o end else t_o end else t_o end end.compact if @md.flag_auto_biblio \ and bibliography.length > 0 data_new=[] bib=sort_bibliography_array_by_deemed_author_year_title(bibliography) biblio_done=[] @data.select do |t_o| if t_o =~/^1~!biblio(?:graphy)?/ bib.each do |c| d=c d.store(:obj, biblio_make(c)) biblio_done << d #biblio_done << { obj: biblio_make(c), id: c[:id] } end else data_new << t_o end end @data=data_new end [@data,biblio_done] end
biblio_format()
click to toggle source
# File lib/sisu/ao_appendices.rb, line 241 def biblio_format def generic(c) cite=%{#{c[:author]}. /{"#{c[:fulltitle]}".}/} cite=(c[:journal]) \ ? cite + %{ #{c[:journal]},} : cite cite=(c[:source]) \ ? cite + %{ #{c[:source]},} : cite cite=(c[:in]) \ ? cite + %{ in #{c[:in]},} : cite cite=(c[:volume]) \ ? cite + %{ #{c[:volume]},} : cite cite=(c[:trans]) \ ? cite + %{ trans. #{c[:trans]},} : cite cite=(c[:editor]) \ ? cite + %{ ed. #{c[:editor]},} : cite cite=(c[:place]) \ ? cite + %{ #{c[:place]},} : cite cite=(c[:publisher]) \ ? cite + %{ #{c[:publisher]},} : cite cite=(c[:year]) \ ? cite + %{ (#{c[:year]})} : cite cite=(c[:pages]) \ ? cite + %{ #{c[:pages]}} : cite cite=(c[:url]) \ ? cite + %{ #{c[:url]}} : cite cite=(c[:note]) \ ? cite + %{ #{c[:note]}} : cite cite end def generic_editor(c) cite=%{#{c[:editor]} ed. /{"#{c[:fulltitle]}".}/} cite=(c[:journal]) \ ? cite + %{ #{c[:journal]}, } : cite cite=(c[:source]) \ ? cite + %{ #{c[:source]}, } : cite cite=(c[:in]) \ ? cite + %{ in #{c[:in]},} : cite cite=(c[:volume]) \ ? cite + %{ #{c[:volume]},} : cite cite=(c[:trans]) \ ? cite + %{ trans. #{c[:trans]},} : cite cite=(c[:place]) \ ? cite + %{ #{c[:place]},} : cite cite=(c[:publisher]) \ ? cite + %{ #{c[:publisher]}} : cite cite=(c[:year]) \ ? cite + %{ (#{c[:year]})} : cite cite=(c[:pages]) \ ? cite + %{ #{c[:pages]}} : cite cite=(c[:url]) \ ? cite + %{ #{c[:url]}} : cite cite=(c[:note]) \ ? cite + %{ #{c[:note]}} : cite cite end self end
biblio_make(cite)
click to toggle source
# File lib/sisu/ao_appendices.rb, line 321 def biblio_make(cite) if cite[:author] biblio_format.generic(cite) elsif cite[:editor] biblio_format.generic_editor(cite) else biblio_format.generic(cite) end end
citation_in_prepared_bibliography(cite)
click to toggle source
# File lib/sisu/ao_appendices.rb, line 120 def citation_in_prepared_bibliography(cite) @cite=cite def generic { is: nil, # :book, :article, :magazine, :newspaper, :blog, :other author_raw: nil, author: nil, author_arr: nil, editor_raw: nil, editor: nil, editor_arr: nil, title: nil, subtitle: nil, fulltitle: nil, language: nil, trans: nil, src: nil, journal: nil, in: nil, volume: nil, edition: nil, year: nil, place: nil, publisher: nil, url: nil, pages: nil, note: nil, #format: nil, #consider list of fields arranged with markup short_name: nil, id: nil, } end def citation_metadata type=:generic if type citation=generic citeblock=@cite.split("\n") citeblock.select do |meta| case meta when /^((?:au|author):\s+)\S+/ #req citation[:author_raw]=/^#{$1}(.+)/.match(meta)[1] when /^((?:ti|title):\s+)\S+/ #req citation[:title]=/^#{$1}(.+)/.match(meta)[1] when /^((?:st|subtitle):\s+)\S+/ citation[:subtitle]=/^#{$1}(.+)/.match(meta)[1] when /^((?:lng|language):\s+)\S+/ citation[:language]=/^#{$1}(.+)/.match(meta)[1] when /^((?:edr?|editor):\s+)\S+/ citation[:editor_raw]=/^#{$1}(.+)/.match(meta)[1] when /^((?:tr|trans(:?lator)?):\s+)\S+/ citation[:editor_raw]=/^#{$1}(.+)/.match(meta)[1] when /^((?:pb|publisher):\s+)\S+/ citation[:publisher]=/^#{$1}(.+)/.match(meta)[1] when /^((?:edn|edition):\s+)\S+/ citation[:edition]=/^#{$1}(.+)/.match(meta)[1] when /^((?:yr|year):\s+)\S+/ #req? citation[:year]=/^#{$1}(.+)/.match(meta)[1] when /^((?:pl|publisher_state):\s+)\S+/ citation[:place]=/^#{$1}(.+)/.match(meta)[1] when /^((?:jo|journal):\s+)\S+/ #req? citation[:journal]=/^#{$1}(.+)/.match(meta)[1] when /^((?:vol?|volume):\s+)\S+/ citation[:volume]=/^#{$1}(.+)/.match(meta)[1] when /^((?:in):\s+)\S+/ citation[:in]=/^#{$1}(.+)/.match(meta)[1] when /^((?:src):\s+)\S+/ citation[:src]=/^#{$1}(.+)/.match(meta)[1] when /^((?:pg|pages?):\s+)\S+/ citation[:pages]=/^#{$1}(.+)/.match(meta)[1] when /^(url:\s+)\S+/ citation[:url]=/^#{$1}(.+)/.match(meta)[1] when /^(note:\s+)\S+/ citation[:note]=/^#{$1}(.+)/.match(meta)[1] when /^((?:sn|shortname):\s+)\S+/ # substitution: (/#{id}/,"#{sn}") citation[:short_name]=/^#{$1}(.+)/.match(meta)[1] when /^(id:\s+)\S+/ # substitution: (/#{id}/,"#{sn}") citation[:id]=/^#{$1}(.+)/.match(meta)[1] end end if citation[:subtitle] citation[:fulltitle] = citation[:title] \ + ' - ' \ + citation[:subtitle] else citation[:fulltitle] = citation[:title] end if citation[:author_raw] citation[:author_arr]=citation[:author_raw].split(/;\s*/) citation[:author]=citation[:author_arr].map do |author| author.gsub(/(.+?),\s+(.+)/,'\2 \1').strip end.join(', ').strip end if citation[:editor_raw] citation[:editor_arr]=citation[:editor_raw].split(/;\s*/) citation[:editor]=citation[:editor_arr].map do |editor| editor.gsub(/(.+?),\s+(.+)/,'\2 \1').strip end.join(', ').strip end citation[:ymd]=if not citation[:year] =~/^[0-9]{4}/ '9999' else citation[:year] end citation[:deemed_author]=if not citation[:author_raw] \ and citation[:editor_raw] citation[:editor_arr][0] elsif citation[:author_raw] citation[:author_arr][0] else SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). warn('Citation needs an author or editor, title: "' \ + citation[:title] + '"') '000' end unless citation[:short_name] citation[:short_name]=%{#{citation[:author]}, "#{citation[:title]}" (#{citation[:date]})} end end citation end self end
citation_metadata()
click to toggle source
# File lib/sisu/ao_appendices.rb, line 152 def citation_metadata type=:generic if type citation=generic citeblock=@cite.split("\n") citeblock.select do |meta| case meta when /^((?:au|author):\s+)\S+/ #req citation[:author_raw]=/^#{$1}(.+)/.match(meta)[1] when /^((?:ti|title):\s+)\S+/ #req citation[:title]=/^#{$1}(.+)/.match(meta)[1] when /^((?:st|subtitle):\s+)\S+/ citation[:subtitle]=/^#{$1}(.+)/.match(meta)[1] when /^((?:lng|language):\s+)\S+/ citation[:language]=/^#{$1}(.+)/.match(meta)[1] when /^((?:edr?|editor):\s+)\S+/ citation[:editor_raw]=/^#{$1}(.+)/.match(meta)[1] when /^((?:tr|trans(:?lator)?):\s+)\S+/ citation[:editor_raw]=/^#{$1}(.+)/.match(meta)[1] when /^((?:pb|publisher):\s+)\S+/ citation[:publisher]=/^#{$1}(.+)/.match(meta)[1] when /^((?:edn|edition):\s+)\S+/ citation[:edition]=/^#{$1}(.+)/.match(meta)[1] when /^((?:yr|year):\s+)\S+/ #req? citation[:year]=/^#{$1}(.+)/.match(meta)[1] when /^((?:pl|publisher_state):\s+)\S+/ citation[:place]=/^#{$1}(.+)/.match(meta)[1] when /^((?:jo|journal):\s+)\S+/ #req? citation[:journal]=/^#{$1}(.+)/.match(meta)[1] when /^((?:vol?|volume):\s+)\S+/ citation[:volume]=/^#{$1}(.+)/.match(meta)[1] when /^((?:in):\s+)\S+/ citation[:in]=/^#{$1}(.+)/.match(meta)[1] when /^((?:src):\s+)\S+/ citation[:src]=/^#{$1}(.+)/.match(meta)[1] when /^((?:pg|pages?):\s+)\S+/ citation[:pages]=/^#{$1}(.+)/.match(meta)[1] when /^(url:\s+)\S+/ citation[:url]=/^#{$1}(.+)/.match(meta)[1] when /^(note:\s+)\S+/ citation[:note]=/^#{$1}(.+)/.match(meta)[1] when /^((?:sn|shortname):\s+)\S+/ # substitution: (/#{id}/,"#{sn}") citation[:short_name]=/^#{$1}(.+)/.match(meta)[1] when /^(id:\s+)\S+/ # substitution: (/#{id}/,"#{sn}") citation[:id]=/^#{$1}(.+)/.match(meta)[1] end end if citation[:subtitle] citation[:fulltitle] = citation[:title] \ + ' - ' \ + citation[:subtitle] else citation[:fulltitle] = citation[:title] end if citation[:author_raw] citation[:author_arr]=citation[:author_raw].split(/;\s*/) citation[:author]=citation[:author_arr].map do |author| author.gsub(/(.+?),\s+(.+)/,'\2 \1').strip end.join(', ').strip end if citation[:editor_raw] citation[:editor_arr]=citation[:editor_raw].split(/;\s*/) citation[:editor]=citation[:editor_arr].map do |editor| editor.gsub(/(.+?),\s+(.+)/,'\2 \1').strip end.join(', ').strip end citation[:ymd]=if not citation[:year] =~/^[0-9]{4}/ '9999' else citation[:year] end citation[:deemed_author]=if not citation[:author_raw] \ and citation[:editor_raw] citation[:editor_arr][0] elsif citation[:author_raw] citation[:author_arr][0] else SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). warn('Citation needs an author or editor, title: "' \ + citation[:title] + '"') '000' end unless citation[:short_name] citation[:short_name]=%{#{citation[:author]}, "#{citation[:title]}" (#{citation[:date]})} end end citation end
generic()
click to toggle source
# File lib/sisu/ao_appendices.rb, line 122 def generic { is: nil, # :book, :article, :magazine, :newspaper, :blog, :other author_raw: nil, author: nil, author_arr: nil, editor_raw: nil, editor: nil, editor_arr: nil, title: nil, subtitle: nil, fulltitle: nil, language: nil, trans: nil, src: nil, journal: nil, in: nil, volume: nil, edition: nil, year: nil, place: nil, publisher: nil, url: nil, pages: nil, note: nil, #format: nil, #consider list of fields arranged with markup short_name: nil, id: nil, } end
generic_editor(c)
click to toggle source
# File lib/sisu/ao_appendices.rb, line 282 def generic_editor(c) cite=%{#{c[:editor]} ed. /{"#{c[:fulltitle]}".}/} cite=(c[:journal]) \ ? cite + %{ #{c[:journal]}, } : cite cite=(c[:source]) \ ? cite + %{ #{c[:source]}, } : cite cite=(c[:in]) \ ? cite + %{ in #{c[:in]},} : cite cite=(c[:volume]) \ ? cite + %{ #{c[:volume]},} : cite cite=(c[:trans]) \ ? cite + %{ trans. #{c[:trans]},} : cite cite=(c[:place]) \ ? cite + %{ #{c[:place]},} : cite cite=(c[:publisher]) \ ? cite + %{ #{c[:publisher]}} : cite cite=(c[:year]) \ ? cite + %{ (#{c[:year]})} : cite cite=(c[:pages]) \ ? cite + %{ #{c[:pages]}} : cite cite=(c[:url]) \ ? cite + %{ #{c[:url]}} : cite cite=(c[:note]) \ ? cite + %{ #{c[:note]}} : cite cite end