5
6
7
8
9
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/bmi/cli.rb', line 5
def self.calc(arguments=[])
options = {
:weight_k => 0,
:height_m => 0,
:weight_p => 0,
:height_i => 0
}
mandatory_options = %w( )
parser = OptionParser.new do |opts|
opts.banner = " Body Mass Index [BMI] help guide\n\n Usage: \#{File.basename($0)} [options]\n\n Options are:\n BANNER\n opts.separator \"\"\n\n opts.on(\"-w\", \"--weight KILOGRAMS\", String,\n \"Your current weight.\",\n \"Pleace introduce your weight in kilograms.\",\n \"Default: ~\") { |arg| options[:weight_k] = arg }\n\n opts.on(\"-b\", \"--height METERS\", String,\n \"How hight you are.\",\n \"Pleace introduce your height in meters.\",\n \"Default: ~\") { |arg| options[:height_m] = arg }\n\n opts.on(\"-W\", \"--Weight POUNDS\", String,\n \"Your current weight.\",\n \"Pleace introduce your weight in pounds.\",\n \"Default: ~\") { |arg| options[:weight_p] = arg }\n\n opts.on(\"-B\", \"--Height INCHES\", String,\n \"How hight you are.\",\n \"Pleace introduce your height in inches.\",\n \"Default: ~\") { |arg| options[:height_i] = arg }\n\n opts.on(\"-h\", \"--help\",\n \"Show this help message.\") { puts opts; exit }\n\n\n error = false\n arguments.each do|v|\n unless v.match(/-[w|b|W|B|h]/) || v.match(/\\d/)\n error = true\n puts \"Use '-h' or '--help' for more help\"\n end\n end\n\n unless (arguments[0] == \"-h\") || (arguments[0] == \"--help\")\n error = true unless (arguments.count == 4)\n end\n\n opts.parse!(arguments) unless error\n\n if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }\n puts opts; exit\n end\n end\n\n return options\nend\n".gsub(/^ /,'')
|