Class: DuperVisor::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/dupervisor/main.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Main

Returns a new instance of Main.



10
11
12
# File 'lib/dupervisor/main.rb', line 10

def initialize(config)
  self.config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



8
9
10
# File 'lib/dupervisor/main.rb', line 8

def config
  @config
end

#contentObject

Returns the value of attribute content.



8
9
10
# File 'lib/dupervisor/main.rb', line 8

def content
  @content
end

#from_formatObject

Returns the value of attribute from_format.



8
9
10
# File 'lib/dupervisor/main.rb', line 8

def from_format
  @from_format
end

Instance Method Details

#report_error(e) ⇒ Object



23
24
25
26
# File 'lib/dupervisor/main.rb', line 23

def report_error(e)
  puts '  Error:'.bold.white + ' Unable to parse input.'.bold.red
  puts 'Details:'.bold.white + " #{e.inspect}".red
end

#runObject



14
15
16
17
18
19
20
21
# File 'lib/dupervisor/main.rb', line 14

def run
  config.validate!
  self.from_format = Detector.new(ARGF.filename).detect
  self.content = Parser.new(ARGF.read).parse(from_format)
  Renderer.new(content.parse_result, config.output).render(config.to)
rescue DuperVisor::Parser::ParseError => e
  report_error(e)
end