class CiteProc::CitationData
Attributes
Public Class Methods
Source
# File lib/citeproc/citation_data.rb, line 128 def initialize(attributes = nil, options = {}) @options = CitationData.defaults.merge(options) @items, @sorted_items = [], [] merge(attributes) end
Public Instance Methods
Source
# File lib/citeproc/citation_data.rb, line 172 def each(&block) if block_given? if sorted? sorted_items.each(&block) else items.each(&block) end self else to_enum end end
Source
# File lib/citeproc/citation_data.rb, line 203 def footnote? options[:footnote] > 0 end
Source
# File lib/citeproc/citation_data.rb, line 134 def initialize_copy(other) @options = other.options.dup @items = other.items.map(&:dup) @sorted_items = other.items.map(&:dup) @id = other.id.dup if other.processed? end
Source
# File lib/citeproc/citation_data.rb, line 225 def inspect "#<CiteProc::CitationData items=[#{length}]>" end
@return [String] a human-readable representation of the citation data
Source
# File lib/citeproc/citation_data.rb, line 141 def merge(other) return self if other.nil? case other when String, /^\s*\{/ other = JSON.parse(other, :symbolize_names => true) when Hash # do nothing when Array other = { :items => other } when Attributes other = other.to_hash else raise ParseError, "failed to merge citation data and #{other.inspect}" end other = convert_from_citeproc(other) items.concat(Array(other.delete(:items)).map { |i| CitationItem.create!(i) }) sorted_items.concat(Array(other.delete(:sorted_items))) properties = other.delete(:options) options.merge!(convert_from_citeproc(Hash[properties])) unless properties.nil? @id = other[:id] if other.has_key?(:id) self end
Also aliased as: update
Source
# File lib/citeproc/citation_data.rb, line 194 def sort!(&block) @sorted_items = items.sort(&block) self end
Source
# File lib/citeproc/citation_data.rb, line 190 def sorted? !sorted_items.empty? end
Source
# File lib/citeproc/citation_data.rb, line 207 def to_citeproc cp = {} cp[CitationData.rb2cp[:items]] = items.map(&:to_citeproc) cp[CitationData.rb2cp[:options]] = { CitationData.rb2cp[:footnote] => index } cp[CitationData.rb2cp[:id]] = id if processed? cp end
Source
# File lib/citeproc/citation_data.rb, line 218 def to_json ::JSON.dump(to_citeproc) end
Also aliased as: to_s
Private Instance Methods
Source
# File lib/citeproc/citation_data.rb, line 231 def convert_from_citeproc(hash) hash = hash.symbolize_keys CitationData.cp2rb.each do |cp, rb| cp = cp.to_sym hash[rb] = hash.delete(cp) if hash.has_key?(cp) end hash end