Module: Ovchipkaart

Defined in:
lib/ovchipkaart.rb,
lib/ovchipkaart/api.rb,
lib/ovchipkaart/setup.rb,
lib/ovchipkaart/parser.rb,
lib/ovchipkaart/scraper.rb,
lib/ovchipkaart/version.rb

Defined Under Namespace

Modules: Setup Classes: Api, ConfigurationError, OvchipkaartError, Parser, Scraper

Constant Summary collapse

MANDATORY_CONFIGURATION =

Configuration

{ username: nil, password: nil }
CONFIGURATIONS_KEYS =
MANDATORY_CONFIGURATION.merge!({})
VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.configObject



18
19
20
# File 'lib/ovchipkaart.rb', line 18

def self.config
  @config
end

.configure(options = {}) ⇒ Object

Configuration with a hash



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ovchipkaart.rb', line 23

def self.configure(options = {})
  MANDATORY_CONFIGURATION.each_key do |mandatory_option|
    unless options.keys.map(&:to_sym).include?(mandatory_option)
      raise ConfigurationError, 'Username and password are mandatory configuration options'
    end
  end

  options.keys.map(&:to_sym).each do |given_configuration_key|
    unless CONFIGURATIONS_KEYS.keys.include? given_configuration_key
      raise ConfigurationError, 'Unknown configuration given'
    end
  end

  options.each { |key, value| @config[key.to_sym] = value }
end

.configure_with(path_to_yaml_file) ⇒ Object

Configuration with a YAML file



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ovchipkaart.rb', line 40

def self.configure_with(path_to_yaml_file)
  begin
    config = YAML::load(IO.read(path_to_yaml_file))
  rescue Errno::ENOENT
    raise ConfigurationError, 'YAML configuration file not found'
  rescue Psych::SyntaxError
    raise ConfigurationError, 'YAML configuration file contains invalid syntax'
  end

  configure(config)
end