Class: Pandoku::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/pandoku/format.rb,
lib/pandoku/lookup_table.rb

Overview

Abstract base class for formats.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Format

Returns a new instance of Format.



18
19
20
21
22
# File 'lib/pandoku/format.rb', line 18

def initialize(options = {})
  @options = self.class.default_options
  keys = @options.keys
  @options.merge!(Hash[options.select {|k, v| keys.include?(k) }])
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/pandoku/format.rb', line 7

def options
  @options
end

Class Method Details

.default_optionsObject



14
15
16
# File 'lib/pandoku/format.rb', line 14

def self.default_options
  {}
end

.inherited(subclass) ⇒ Object



26
27
28
# File 'lib/pandoku/lookup_table.rb', line 26

def self.inherited(subclass)
  Formats::LOOKUP_TABLE << subclass
end

.nameObject

Raises:

  • (NotImplementedError)


9
10
11
12
# File 'lib/pandoku/format.rb', line 9

def self.name
  raise NotImplementedError,
        'Format.name should be overrided to return Symbol'
end

Instance Method Details

#clioptsObject



24
25
26
27
28
# File 'lib/pandoku/format.rb', line 24

def cliopts
  self.options.select {|k, v| v } \
              .collect {|p| %<--#{p[0].to_s.gsub('_', '-')}> +
                            (p[1] != true ? %<=#{p[1]}> : '') }
end