Class: Pekky::Format::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/pekky/format.rb

Overview

The wrapper class acts as a container for a set of renderers or filters. It’s most essential job is to allow syntax like this:

Format::Formatters.textile("h1. blah")

This class should never be instanced, or accessed directly. Instead, we use the Renderers and Filters subclasses.

Direct Known Subclasses

Filters, Formatters

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.call_withObject

Returns the value of attribute call_with.



27
28
29
# File 'lib/pekky/format.rb', line 27

def call_with
  @call_with
end

.klassesObject

Returns the value of attribute klasses.



27
28
29
# File 'lib/pekky/format.rb', line 27

def klasses
  @klasses
end

Class Method Details

.[](name) ⇒ Object

Shortcut for accessing a transformer class by name.



36
37
38
# File 'lib/pekky/format.rb', line 36

def self.[](name)
  self.klasses[name]
end

.add(name, klass) ⇒ Object

Adds a transformer to the existing collection.



31
32
33
# File 'lib/pekky/format.rb', line 31

def self.add(name, klass)
  (self.klasses ||= {})[name] = klass
end

.eachObject

An iterator for looping over the transformer. The block will recieve the name and the actual class.



52
53
54
# File 'lib/pekky/format.rb', line 52

def self.each
  self.klasses.each { |k, v| yield k, v }
end

.keysObject

Returns all the names of the transformers.



41
42
43
# File 'lib/pekky/format.rb', line 41

def self.keys
  self.klasses.keys
end

.method_missing(name, *args) ⇒ Object

Method missing is used here to provide nice syntax for accessing transformer as methods.



58
59
60
61
62
63
64
# File 'lib/pekky/format.rb', line 58

def self.method_missing(name, *args)
  if self.klasses[name]
    self.klasses[name].send(self.call_with, *args)
  else
    super
  end
end

.valuesObject

Returns the actual transformers themselves.



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

def self.values
  self.klasses.values
end