Class: Af::OptionParser::OptionType

Inherits:
Object
  • Object
show all
Defined in:
lib/fiksu-af/option_parser/option_type.rb

Constant Summary collapse

@@types =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, short_name, argument_note, evaluate_method, handler_method) ⇒ OptionType

Returns a new instance of OptionType.



11
12
13
14
15
16
17
18
# File 'lib/fiksu-af/option_parser/option_type.rb', line 11

def initialize(name, short_name, argument_note, evaluate_method, handler_method)
  @name = name
  @short_name = short_name
  @argument_note = argument_note
  @evaluate_method = evaluate_method
  @handler_method = handler_method
  @@types << self
end

Instance Attribute Details

#argument_noteObject (readonly)

Returns the value of attribute argument_note.



3
4
5
# File 'lib/fiksu-af/option_parser/option_type.rb', line 3

def argument_note
  @argument_note
end

#evaluate_methodObject (readonly)

Returns the value of attribute evaluate_method.



3
4
5
# File 'lib/fiksu-af/option_parser/option_type.rb', line 3

def evaluate_method
  @evaluate_method
end

#handler_methodObject (readonly)

Returns the value of attribute handler_method.



3
4
5
# File 'lib/fiksu-af/option_parser/option_type.rb', line 3

def handler_method
  @handler_method
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/fiksu-af/option_parser/option_type.rb', line 3

def name
  @name
end

#short_nameObject (readonly)

Returns the value of attribute short_name.



3
4
5
# File 'lib/fiksu-af/option_parser/option_type.rb', line 3

def short_name
  @short_name
end

Class Method Details

.find_by_short_name(short_name) ⇒ Object



36
37
38
# File 'lib/fiksu-af/option_parser/option_type.rb', line 36

def self.find_by_short_name(short_name)
  return types.find{ |t| t.short_name == short_name }
end

.find_by_value(value) ⇒ Object



32
33
34
# File 'lib/fiksu-af/option_parser/option_type.rb', line 32

def self.find_by_value(value)
  return types.find{ |t| t.handle?(value) }
end

.typesObject


*** Class Methods *** ++++++++++++++++++++++



24
25
26
# File 'lib/fiksu-af/option_parser/option_type.rb', line 24

def self.types
  return @@types
end

.valid_option_type_namesObject



28
29
30
# File 'lib/fiksu-af/option_parser/option_type.rb', line 28

def self.valid_option_type_names
  return types.map(&:short_name)
end

Instance Method Details

#evaluate_argument(argument, option) ⇒ Object


*** Instance Methods *** +++++++++++++++++++++++++



44
45
46
47
48
49
# File 'lib/fiksu-af/option_parser/option_type.rb', line 44

def evaluate_argument(argument, option)
  if @evaluate_method.is_a? Symbol
    return argument.send(@evaluate_method)
  end
  return @evaluate_method.call(argument, option)
end

#handle?(value) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
# File 'lib/fiksu-af/option_parser/option_type.rb', line 51

def handle?(value)
  if @handler_method.is_a? Class
    return value.is_a? @handler_method
  end
  return @handler_method.call(value)
end