module Mirador::Formatting

Public Class Methods

included(base) click to toggle source
# File lib/mirador/formatter.rb, line 28
def self.included(base)
  base.extend(ClassMethods)
  Formatting.class_variable_set(:@@formatter, Formatter.new)
end

Protected Instance Methods

format_items(dtype, items) click to toggle source
# File lib/mirador/formatter.rb, line 35
def format_items dtype, items
  Hash[items.each_with_index.map do |kv, idx|
    format_item(dtype, idx, kv[0], kv[1])
  end.flatten(1)]
end

Private Instance Methods

format_item(dtype, idx, id, data) click to toggle source
# File lib/mirador/formatter.rb, line 43
def format_item dtype, idx, id, data
  formatted, dt = get_format(data, dtype.to_sym)

  [
    ["#{ dt }[#{ idx }][id]", id],
    ["#{ dt }[#{ idx }][data]", formatted],
  ]
end
get_format(item, dtype) click to toggle source
# File lib/mirador/formatter.rb, line 52
def get_format item, dtype
  dtype = dtype.to_sym

  if not @@formatter.respond_to? dtype
    raise ApiError, "unsupported datatype: #{ dtype }"
  end

  return @@formatter.send(dtype, item), @@format_map[dtype]
end