Class: CI::Syntax::Tool::FormatFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/ci-syntax-tool/format_factory.rb

Overview

CI:Syntax::Tool::FormatFactory

Identifies and loads the Format classes, and

creates instances as needed.

Class Method Summary collapse

Class Method Details

.all_format_classesObject



20
21
22
# File 'lib/ci-syntax-tool/format_factory.rb', line 20

def self.all_format_classes
  Format::Base.descendant_classes
end

.all_format_namesObject



24
25
26
27
28
29
30
31
# File 'lib/ci-syntax-tool/format_factory.rb', line 24

def self.all_format_names
  class_names = all_format_classes.map(&:name)
  short_names = class_names.map do |name|
    name.split('::').last
  end
  public_names = short_names.reject {|e| e == 'MockFormat'}
  public_names
end

.create(lang_name, io, args = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ci-syntax-tool/format_factory.rb', line 38

def self.create(lang_name, io, args = {})
  unless io.respond_to? :puts
    if io == '-'
      io = $stdout
    else
      # Ensure containing dir exists
      FileUtils.mkdir_p File.dirname(io)
      io = File.open(io, File::WRONLY | File::CREAT)
    end
  end
    
  const_get('CI::Syntax::Tool::Format::' + lang_name).new(io, args)
end

.valid_format?(proposed) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/ci-syntax-tool/format_factory.rb', line 33

def self.valid_format?(proposed)
  permitted_names = all_format_names << 'MockFormat'
  permitted_names.include?(proposed)
end