Class: ConfigParser

Inherits:
Object
  • Object
show all
Defined in:
lib/monzo/config_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(path_to_config) ⇒ ConfigParser

Returns a new instance of ConfigParser.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/monzo/config_parser.rb', line 5

def initialize(path_to_config)
  @path_to_config = path_to_config
  @parsed = nil

  @parsed = begin
    YAML.load(File.open(@path_to_config))
  rescue ArgumentError => e
    puts "Could not parse YAML: #{e.message}"
  end if File.exist?(@path_to_config)

end

Instance Method Details

#parseObject



17
18
19
20
# File 'lib/monzo/config_parser.rb', line 17

def parse
  return nil unless valid?
  @parsed
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
# File 'lib/monzo/config_parser.rb', line 22

def valid?
  return nil if @parsed.nil?
  return nil if @parsed['access_token'].nil?
  return nil if @parsed['account_id'].nil?
  return nil if @parsed['user_id'].nil?

  true
end