class Photomosaic::Options

Constants

KEYS
REQUIRED_KEYS

Public Class Methods

new(options) click to toggle source
# File lib/photomosaic/options.rb, line 34
def initialize(options)
  @options = options
end
parse(argv) click to toggle source
# File lib/photomosaic/options.rb, line 25
def self.parse(argv)
  options = default_options
  parser(options).parse(argv)
  options[:api_key] = api_key
  check_options(options)

  self.new(options)
end

Private Class Methods

api_key() click to toggle source
# File lib/photomosaic/options.rb, line 44
def self.api_key
  ENV["PHOTOMOSAIC_API_KEY"]
end
check_options(options) click to toggle source
# File lib/photomosaic/options.rb, line 48
def self.check_options(options)
  REQUIRED_KEYS.each do |key|
    raise OptionParser::MissingArgument, key unless options[key.to_sym]
  end
end
default_options() click to toggle source
# File lib/photomosaic/options.rb, line 54
def self.default_options
  {
   color_model: :rgb,
   colors: 16,
   height: 200,
   level: 4,
   results: 50,
   search_engine: Photomosaic::SearchEngine::Bing,
   width: 200,
  }
end
parser(options) click to toggle source
# File lib/photomosaic/options.rb, line 66
def self.parser(options)
  OptionParser.new do |opt|
    opt.on("-b", "--base_image=VAL", "Path of base image") { |val| options[:base_image] = File.expand_path(val) }
    opt.on("-c", "--colors=VAL", "Number of colors") { |val| options[:colors] = val.to_i }
    opt.on("-h", "--height=VAL", "Height of output image") { |val| options[:height] = val.to_i }
    opt.on("-k", "--keyword=VAL", "Keyword") { |val| options[:keyword] = val }
    opt.on("-l", "--level=VAL", "Color level") { |val| options[:level] = val.to_i }
    opt.on("-o", "--output_path=VAL", "Path of mosaic image") { |val| options[:output_path] = File.expand_path(val) }
    opt.on("-r", "--results=VAL", "Number of results") { |val| options[:results] = val.to_i }
    opt.on("-w", "--width=VAL", "Width of output image") { |val| options[:width] = val.to_i }
    opt.on("--hsv", "Use HSV") { |val| options[:color_model] = :hsv }
  end
end