Class: Orange::Options

Inherits:
Object show all
Defined in:
lib/orange-core/magick.rb

Overview

Simple class for evaluating options and allowing us to access them.

Instance Method Summary collapse

Constructor Details

#initialize(*options, &block) ⇒ Options

Returns a new instance of Options.



151
152
153
154
155
156
# File 'lib/orange-core/magick.rb', line 151

def initialize(*options, &block)
  @core = options.first if(options.size > 0 && options.first.kind_of?(Orange::Core))
  @options = options.extract_options!
  @options ||= {}
  instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/orange-core/magick.rb', line 167

def method_missing(key, *args)
  return (@options[key.to_s.gsub(/\?$/, '').to_sym].eql?(true)) if key.to_s.match(/\?$/)
  if args.empty?
    @options[key.to_sym]
  elsif(@core && @core.respond_to?(key.to_sym))
    @core.__send__(key, *args)
  elsif(key.to_s.match(/\=$/))
    @options[key.to_s.gsub(/\=$/, '').to_sym] = (args.size == 1 ? args.first : args)
  else
    @options[key.to_sym] = (args.size == 1 ? args.first : args)
  end
end

Instance Method Details

#hashObject



158
159
160
# File 'lib/orange-core/magick.rb', line 158

def hash
  @options
end

#load(*args) ⇒ Object

Load needs fixing up.



163
164
165
# File 'lib/orange-core/magick.rb', line 163

def load(*args)
  @core.load(*args)
end