Module: Benry::CmdOpt

Defined in:
lib/benry/cmdopt.rb

Overview

Defined Under Namespace

Classes: Facade, OptionError, Parser, Schema, SchemaError, SchemaItem

Constant Summary collapse

VERSION =
'$Release: 2.4.0 $'.split()[1]
PARAM_TYPES =
{
  String => proc {|val|
    val
  },
  Integer => proc {|val|
    #; [!6t8cs] converts value into integer.
    #; [!nzwc9] raises error when failed to convert value into integer.
    val =~ /\A[-+]?\d+\z/  or
      raise "Integer expected."
    val.to_i
  },
  Float => proc {|val|
    #; [!gggy6] converts value into float.
    #; [!t4elj] raises error when faield to convert value into float.
    val =~ /\A[-+]?(\d+\.\d*|\.\d+)\z/  or
      raise "Float expected."
    val.to_f
  },
  TrueClass => proc {|val|
    #; [!47kx4] converts 'true'/'on'/'yes' into true.
    #; [!3n810] converts 'false'/'off'/'no' into false.
    #; [!h8ayh] raises error when failed to convert value into true nor false.
    case val
    when /\A(?:true|on|yes)\z/i  ; true
    when /\A(?:false|off|no)\z/i ; false
    else
      raise "Boolean expected."
    end
  },
  Date => proc {|val|
    #; [!sru5j] converts 'YYYY-MM-DD' into date object.
    #; [!h9q9y] raises error when failed to convert into date object.
    #; [!i4ui8] raises error when specified date not exist.
    val =~ /\A(\d\d\d\d)-(\d\d?)-(\d\d?)\z/  or
      raise "Invalid date format (ex: '2000-01-01')"
    begin
      Date.new($1.to_i, $2.to_i, $3.to_i)
    rescue ArgumentError => ex
      raise "Date not exist."
    end
  },
}
OPTIONS_CLASS =
Hash
SCHEMA_CLASS =
Schema
PARSER_CLASS =
Parser

Class Method Summary collapse

Class Method Details

.newObject



29
30
31
32
# File 'lib/benry/cmdopt.rb', line 29

def self.new()
  #; [!7kkqv] creates Facade object.
  return Facade.new
end