Sha256: 5527c3fa936470ad7121f0b5c8d9a111cc2e3897443212563b2b374a9994c925

Contents?: true

Size: 912 Bytes

Versions: 10

Compression:

Stored size: 912 Bytes

Contents

module CiteProc
	module Abbreviate

		attr_accessor :namespace

		def abbreviations
			@abbreviations ||= { :default => {} }
		end

		def abbreviations=(abbreviations)
			@abbreviations = case abbreviations
				when ::String
					::JSON.parse(abbreviations, :symbolize_names => true)
				when ::Hash
					abbreviations.deep_copy.symbolize_keys
				else
					raise ArgumentError, "failed to set abbreviations from #{abbreviations.inspect}"
				end
		end

		# @overload abbreviate(namespace = :default, context, word)
		def abbreviate(*arguments)
			raise ArgumentError, "wrong number of arguments (#{arguments.length} for 2..3)" unless
        (2..3).include?(arguments.length)

			arguments.unshift(namespace || :default) if arguments.length < 3

      arguments[0] = arguments[0].to_sym
      arguments[1] = arguments[1].to_sym

			abbreviations.deep_fetch(*arguments)
		end
		alias abbrev abbreviate

	end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
citeproc-1.0.10 lib/citeproc/abbreviate.rb
citeproc-1.0.9 lib/citeproc/abbreviate.rb
citeproc-1.0.8 lib/citeproc/abbreviate.rb
citeproc-1.0.7 lib/citeproc/abbreviate.rb
citeproc-1.0.6 lib/citeproc/abbreviate.rb
citeproc-1.0.5 lib/citeproc/abbreviate.rb
citeproc-1.0.4 lib/citeproc/abbreviate.rb
citeproc-1.0.3 lib/citeproc/abbreviate.rb
citeproc-1.0.2 lib/citeproc/abbreviate.rb
citeproc-1.0.1 lib/citeproc/abbreviate.rb