Class: Geoptima::Options
- Inherits:
-
Object
- Object
- Geoptima::Options
- Defined in:
- lib/geoptima/options.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #add(*args, &block) ⇒ Object
-
#initialize(debug = nil) ⇒ Options
constructor
A new instance of Options.
- #method_missing(symbol, *args, &block) ⇒ Object
- #process(a) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(debug = nil) ⇒ Options
Returns a new instance of Options.
17 18 19 20 21 |
# File 'lib/geoptima/options.rb', line 17 def initialize(debug=nil) @debug = debug @args = [] @options = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
26 27 28 29 |
# File 'lib/geoptima/options.rb', line 26 def method_missing(symbol,*args,&block) puts "Adding option processing for: #{symbol}" if(debug) @options[symbol.to_s] = block end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
15 16 17 |
# File 'lib/geoptima/options.rb', line 15 def args @args end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
15 16 17 |
# File 'lib/geoptima/options.rb', line 15 def debug @debug end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/geoptima/options.rb', line 15 def @options end |
Class Method Details
.process_args(debug = nil) {|options| ... } ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/geoptima/options.rb', line 46 def self.process_args(debug=nil) = Options.new(debug) .add('f') {$flush_stdout = true} .add('v') {$print_version = true} .add('w') {$verbose = true} .add('d') {$debug = true} .add('h') {$help = true} puts "Processing options: #{}" if(debug) yield if(block_given?) while arg = ARGV.shift do if arg =~ /^\-(\w+)/ $1.split(//).each do |a| .process a end else .args << arg end end puts "Geoptima Gem Version: #{Geoptima::VERSION}" if($print_version) STDOUT.sync if($flush_stdout) .args end |
Instance Method Details
#add(*args, &block) ⇒ Object
22 23 24 25 |
# File 'lib/geoptima/options.rb', line 22 def add(*args,&block) puts "Adding option processing for: #{args[0]}" if(debug) @options[args[0].to_s] = block end |
#process(a) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/geoptima/options.rb', line 30 def process(a) puts "Looking for match to option #{a}" if(debug) @options.each do |opt,block| puts "Comparing option #{a} to known option #{opt}" if(debug) if opt === a puts "Calling block for option #{a}: #{block.inspect}" if(debug) block.call return end end puts "Unknown option: -#{a}" end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/geoptima/options.rb', line 42 def to_s "Options[#{@options.keys.sort.join(', ')}]: #{args.join(', ')}" end |