Module: Wasserstand::Commandline

Defined in:
lib/wasserstand/commandline.rb

Class Method Summary collapse

Class Method Details

.get(params = []) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wasserstand/commandline.rb', line 3

def self.get(params = [])
  case params.size
  when 0
    present_waterway(Wasserstand::Waterway.all)
  when 1 # "Elbe" or "Dresden"
    waterway = Wasserstand::Waterway[params.first]

    if waterway
      present_waterway(waterway)
    else
      # not a waterway, treat it as level
      present_level(Wasserstand::Level[params.first])
    end
  when 2 # "Elbe Dresden" or "Ilm Ilmenau"
    if waterway = Wasserstand::Waterway[params.first]
      present_level(waterway.levels[params.last])
    else
      STDERR.puts "No matching waterway found."
    end
  else
    raise "Unexpected number of parameters."
  end
end