Module: Card::Format::Registration
- Included in:
- Card::Format
- Defined in:
- lib/card/format/registration.rb
Overview
handles format registry, tracking which formats (html, css, json, etc) are available
Instance Method Summary collapse
- #class_from_name(formatname) ⇒ Object
- #format_ancestry ⇒ Object
- #format_class(opts) ⇒ Object
- #format_class_name(format) ⇒ Object
- #new(card, opts = {}) ⇒ Object
- #register(format) ⇒ Object
- #symbol ⇒ Object (also: #to_sym)
Instance Method Details
#class_from_name(formatname) ⇒ Object
34 35 36 37 38 39 40 |
# 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 |
#format_ancestry ⇒ Object
42 43 44 45 46 |
# File 'lib/card/format/registration.rb', line 42 def format_ancestry ancestry = [self] ancestry += superclass.format_ancestry unless self == Card::Format ancestry end |
#format_class(opts) ⇒ Object
20 21 22 23 24 25 |
# 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 |
#format_class_name(format) ⇒ Object
27 28 29 30 31 32 |
# 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 |
#new(card, opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 |
# 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 |
#register(format) ⇒ Object
6 7 8 9 |
# File 'lib/card/format/registration.rb', line 6 def register format registered << format.to_s self.symbol = format end |
#symbol ⇒ Object Also known as: to_sym
48 49 50 |
# File 'lib/card/format/registration.rb', line 48 def symbol @symbol ||= symbol_from_classname end |