Class: Tiling::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/tiling/option.rb

Overview

Public: Set the options.

Instance Method Summary collapse

Constructor Details

#initializeOption

Returns a new instance of Option.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tiling/option.rb', line 10

def initialize
  @options = {horizontal: false, vertical: false, version: false }
  optparse = OptionParser.new do|opts|
    opts.on( '-H', '--horizontal', 'Horizontal layout' ) do
      @options[:horizontal] = true
    end
    opts.on( '-V', '--vertical', 'Vertical layout' ) do
      @options[:vertical] = true
    end
    opts.on( '-v', '--version', 'Print version number and exit' ) do
      @options[:version] = true
    end
    opts.on( '-h', '--help', 'Display this screen' ) do
      puts opts
      exit
    end
  end

  begin
    optparse.parse!
  rescue OptionParser::InvalidOption => e
    puts e.to_s
    exit 1
  end

  print_version if @options[:version]
end

Instance Method Details

#[](key) ⇒ Object



38
39
40
# File 'lib/tiling/option.rb', line 38

def [](key)
  @options[key]
end