class RedditImageDownloader::OptionParser

Constants

DAYS_DESC
DAYS_FORMATS
DEFAULT_OPTIONS
HEIGHT_DESC
HEIGHT_FORMATS
HELP_DESC
HELP_FORMATS
PAGES
PAGE_DESC
PAGE_FORMATS
PATH_DESC
PATH_FORMATS
SUBREDDIT_DESC
SUBREDDIT_FORMATS
VERSION_DESC
VERSION_FORMATS
WIDTH_DESC
WIDTH_FORMATS

Attributes

args[RW]
options[RW]

Public Class Methods

new(args) click to toggle source
# File lib/reddit_image_downloader/option_parser.rb, line 47
def initialize(args)
  @args = args
  @options = DEFAULT_OPTIONS.dup
end
parse!(*args) click to toggle source
# File lib/reddit_image_downloader/option_parser.rb, line 43
def self.parse!(*args)
  new(*args).tap(&:parse!)
end

Public Instance Methods

docs() click to toggle source
# File lib/reddit_image_downloader/option_parser.rb, line 56
def docs
  parser.to_s
end
parse!() click to toggle source
# File lib/reddit_image_downloader/option_parser.rb, line 52
def parse!
  parser.parse!(args)
end
parser() click to toggle source
# File lib/reddit_image_downloader/option_parser.rb, line 60
def parser
  @parser ||= ::OptionParser.new do |parser|
    parser.banner = BANNER

    parser.on(*SUBREDDIT_FORMATS, Array, SUBREDDIT_DESC) do |subreddits|
      options[:subreddits] += subreddits
    end

    parser.on(*PATH_FORMATS, PATH_DESC) do |destination|
      options[:destination] = destination
    end

    parser.on(*WIDTH_FORMATS, Integer, WIDTH_DESC) do |min_width|
      options[:min_width] = min_width
    end

    parser.on(*HEIGHT_FORMATS, Integer, HEIGHT_DESC) do |min_height|
      options[:min_height] = min_height
    end

    parser.on(*PAGE_FORMATS, PAGES, PAGE_DESC) do |page|
      options[:page] = page
    end

    parser.on(*DAYS_FORMATS, Integer, DAYS_DESC) do |days|
      options[:max_age] = days
    end

    parser.on_tail(*VERSION_FORMATS, VERSION_DESC) do
      options[:subcommand] = :version
    end

    parser.on_tail(*HELP_FORMATS, HELP_DESC) do
      options[:subcommand] = :help
    end
  end
end