Class: Makimono::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/makimono/converter.rb,
lib/makimono/converter/markdown.rb,
lib/makimono/converter/markdown/commonmarker.rb,
lib/makimono/converter/markdown/fuji_markdown.rb

Defined Under Namespace

Classes: Markdown

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(converters) ⇒ Converter

Returns a new instance of Converter.



22
23
24
# File 'lib/makimono/converter.rb', line 22

def initialize(converters)
  @converters = converters
end

Instance Attribute Details

#convertersObject (readonly)

Returns the value of attribute converters.



20
21
22
# File 'lib/makimono/converter.rb', line 20

def converters
  @converters
end

Class Method Details

.from_config(config) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/makimono/converter.rb', line 7

def self.from_config(config)
  klasses = if config[:converters] == ['Markdown']
              [Markdown]
            else
              config[:converters].map do |name|
                const_get(name.to_s)
              rescue NameError
                raise InvalidConverterError, "Invalid converter configuration: #{name}"
              end
            end
  new(klasses.map { |klass| klass.new(config) })
end

Instance Method Details

#convert(resource) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/makimono/converter.rb', line 26

def convert(resource)
  converters.inject(resource) do |res, converter|
    if converter.convertible?(res)
      converter.convert(res)
    else
      res
    end
  end
end