Class: PostCL::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/postcl/command.rb

Direct Known Subclasses

Status, Volg

Defined Under Namespace

Classes: UnknownCommandError

Constant Summary collapse

ARG_MATCH =
{
  barcode: /(3S|KG)[A-Z0-9]{13}/,
  postcode: /[0-9]{4}[a-zA-Z]{2}/
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Command

Returns a new instance of Command.



12
13
14
15
16
# File 'lib/postcl/command.rb', line 12

def initialize(session)
  @args = session.args
  @prompt = session.prompt
  @store = session.store
end

Class Method Details

.run(session) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/postcl/command.rb', line 31

def self.run(session)
  if session.args["status"]
    Status.new(session).run
  # elsif post.args["info"]
  #   Info.new(post).run
  elsif post.args["volg"]
    Volg.new(session).run
  else
    raise UnknownCommandError
  end
end

.validate_args(args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/postcl/command.rb', line 18

def self.validate_args(args)
  args.each_key do |key|
    key_sym = key[1...-1].to_sym
    if ARG_MATCH.keys.include?(key_sym)
      args[key].each do |arg|
        next if arg.match(ARG_MATCH[key_sym])
        puts "Ongeldige #{key_sym}: #{arg}"
        exit 1
      end
    end
  end
end