Class: Uberinstaller::Parser
- Inherits:
-
Object
- Object
- Uberinstaller::Parser
- Includes:
- Loggable
- Defined in:
- lib/uberinstaller/parser.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
an Hash containing data after parsing.
-
#file ⇒ Object
the file to be parsed.
Instance Method Summary collapse
- #debug ⇒ Object
-
#initialize(file, perform_parse = true) ⇒ Parser
constructor
Create the parser.
- #run ⇒ Object
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
#data ⇒ Object (readonly)
an Hash containing data after parsing
16 |
# File 'lib/uberinstaller/parser.rb', line 16 attr_accessor :file |
#file ⇒ Object
the file to be parsed
16 17 18 |
# File 'lib/uberinstaller/parser.rb', line 16 def file @file end |
Instance Method Details
#debug ⇒ Object
34 35 36 |
# File 'lib/uberinstaller/parser.rb', line 34 def debug @json end |
#run ⇒ Object
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 |