module Card::Format::Registration

Public Instance Methods

class_from_name(formatname) click to toggle source
# File lib/card/format/registration.rb, line 32
def class_from_name formatname
  if formatname == "Format"
    Card::Format
  else
    Card::Format.const_get formatname
  end
end
format_ancestry() click to toggle source
# File lib/card/format/registration.rb, line 40
def format_ancestry
  ancestry = [self]
  ancestry += superclass.format_ancestry unless self == Card::Format
  ancestry
end
format_class(opts) click to toggle source
# File lib/card/format/registration.rb, line 18
def format_class opts
  return opts[:format_class] if opts[:format_class]

  format = opts[:format] || :html
  class_from_name format_class_name(format)
end
format_class_name(format) click to toggle source
# File lib/card/format/registration.rb, line 25
def format_class_name format
  format = format.to_s
  format = "" if format == "base"
  format = aliases[format] if aliases[format]
  "#{format.camelize}Format"
end
new(card, opts={}) click to toggle source
Calls superclass method
# File lib/card/format/registration.rb, line 9
def new card, opts={}
  if self != Format
    super
  else
    klass = format_class opts
    self == klass ? super : klass.new(card, opts)
  end
end
register(format) click to toggle source
# File lib/card/format/registration.rb, line 4
def register format
  registered << format.to_s
  self.symbol = format
end
symbol() click to toggle source
# File lib/card/format/registration.rb, line 46
def symbol
  @symbol ||= symbol_from_classname
end
Also aliased as: to_sym
to_sym()
Alias for: symbol

Private Instance Methods

symbol_from_classname() click to toggle source
# File lib/card/format/registration.rb, line 53
def symbol_from_classname
  match = to_s.match(/::(?<format>[^:]+)Format/)
  raise "no symbol for #{self.class}" unless match

  match[:format].underscore.to_sym
end