Sha256: 7a7b5251cdddee57269f769e090c5f8be18d7b0474aedf79056d15997f7ee899
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
# Some extension and helper methods. # # Copyright (c) Peter Lane, 2012-13. # Released under Open Works License, 0.9.2 module AsciidoctorBibliographyArrayExtensions # Retrieve the third item of an array # Note: no checks for validity def third self[2] end # Join items in array using commas and 'and' on last item def comma_and_join if size < 2 return self.join("") end result = "" self.each_with_index do |item, index| if index.zero? result << item elsif index == size-1 result << " and #{item}" else result << ", #{item}" end end return result end end # monkey patch the extension methods to Array class Array include AsciidoctorBibliographyArrayExtensions end # Converts html output produced by citeproc to asciidoc markup module StringHtmlToAsciiDoc def html_to_asciidoc r = self.gsub(/<\/?i>/, '_') r = r.gsub(/<\/?b>/, '*') r = r.gsub(/<\/?span.*?>/, '') r = r.gsub(/\{|\}/, '') r end end # Provides a check that a string is in integer # Taken from: # http://stackoverflow.com/questions/1235863/test-if-a-string-is-basically-an-integer-in-quotes-using-ruby module IntegerCheck def is_i? !!(self =~ /^[-+]?[0-9]+$/) end end # monkey patch the extension methods into String class String include StringHtmlToAsciiDoc include IntegerCheck end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
asciidoctor-bibliography-0.1 | deprecated/asciidoctor-bibliography/extensions.rb |
asciidoctor-bibliography-0.0.1.dev | deprecated/asciidoctor-bibliography/extensions.rb |