Class: Uberinstaller::Parser

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/uberinstaller/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

configure_logger_for, #logger, logger_for

Constructor Details

#initialize(file, perform_parse = true) ⇒ Parser

Create the parser



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/uberinstaller/parser.rb', line 20

def initialize(file, perform_parse = true)
  if File.exists?(file)
    @file = file
  else
    raise Uberinstaller::Exception::ParserArgumentError, file
  end

  @json = nil
  @data = nil

  run if perform_parse
  self
end

Instance Attribute Details

#dataObject (readonly)

an Hash containing data after parsing



16
# File 'lib/uberinstaller/parser.rb', line 16

attr_accessor :file

#fileObject

the file to be parsed



16
17
18
# File 'lib/uberinstaller/parser.rb', line 16

def file
  @file
end

Instance Method Details

#debugObject



34
35
36
# File 'lib/uberinstaller/parser.rb', line 34

def debug
  @json
end

#runObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/uberinstaller/parser.rb', line 38

def run
  begin
    @json = IO.read(@file)
    # Comments are stripped out! FUCK YEAH!
    @data = JSON.parse @json, :symbolize_names => true
  rescue JSON::ParserError
    raise Uberinstaller::Exception::JsonParseError, @file
  else
    @data
  end
end