module Card::Format::Registration
handles format registry, tracking which formats (html, css, json, etc) are available
Public Instance Methods
Source
# File lib/card/format/registration.rb, line 34 def class_from_name formatname if formatname == "Format" Card::Format else Card::Format.const_get formatname end end
Source
# File lib/card/format/registration.rb, line 42 def format_ancestry ancestry = [self] ancestry += superclass.format_ancestry unless self == Card::Format ancestry end
Source
# File lib/card/format/registration.rb, line 20 def format_class opts return opts[:format_class] if opts[:format_class] format = opts[:format] || :html class_from_name format_class_name(format) end
Source
# File lib/card/format/registration.rb, line 27 def format_class_name format format = format.to_s format = "" if format == "base" format = aliases[format] if aliases[format] "#{format.camelize}Format" end
Source
# File lib/card/format/registration.rb, line 11 def new card, opts={} if self == Format klass = format_class opts self == klass ? super : klass.new(card, opts) else super end end
Calls superclass method
Source
# File lib/card/format/registration.rb, line 6 def register format registered << format.to_s self.symbol = format end
Source
# File lib/card/format/registration.rb, line 48 def symbol @symbol ||= symbol_from_classname end
Also aliased as: to_sym
Private Instance Methods
Source
# File lib/card/format/registration.rb, line 55 def symbol_from_classname match = to_s.match(/::(?<format>[^:]+)Format/) raise "no symbol for #{self.class}" unless match match[:format].underscore.to_sym end