Module: Card::Format::Registration

Included in:
Card::Format
Defined in:
lib/card/format/registration.rb

Instance Method Summary collapse

Instance Method Details

#class_from_name(formatname) ⇒ Object



32
33
34
35
36
37
38
# 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_ancestryObject



40
41
42
43
44
# 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) ⇒ Object



18
19
20
21
22
23
# 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) ⇒ Object



25
26
27
28
29
30
# 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 = {}) ⇒ Object



9
10
11
12
13
14
15
16
# 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) ⇒ Object



4
5
6
7
# File 'lib/card/format/registration.rb', line 4

def register format
  registered << format.to_s
  self.symbol = format
end

#symbolObject Also known as: to_sym



46
47
48
# File 'lib/card/format/registration.rb', line 46

def symbol
  @symbol ||= symbol_from_classname
end