Class: CTioga2::MetaBuilder::Types::ListParameter

Inherits:
CTioga2::MetaBuilder::Type show all
Defined in:
lib/ctioga2/metabuilder/types/lists.rb

Overview

A list of symbols. A hash :list must be provided that states the correspondance between the legal symbols that can be accepted by this parameter and their “english” name. This parameter can typically be used to prompt the user for different choices.

Instance Attribute Summary

Attributes inherited from CTioga2::MetaBuilder::Type

#namespace, #namespace_lookup, #passthrough, #re_shortcuts, #shortcuts, #type

Instance Method Summary collapse

Methods inherited from CTioga2::MetaBuilder::Type

#boolean?, #default_value, from_string, get_param_type, get_type, #option_parser_long_option, #option_parser_option, #string_to_type, type_name, #type_to_string

Constructor Details

#initialize(type) ⇒ ListParameter

Returns a new instance of ListParameter.



82
83
84
85
86
87
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 82

def initialize(type)
  super
  raise "type must have a :list key" unless type.has_key?(:list)
  # We make a copy for our own purposes.
  @hash = type[:list].dup
end

Instance Method Details

#string_to_type_internal(str) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 93

def string_to_type_internal(str)
  if @hash.has_key?(str.to_sym)
    return str.to_sym
  else
    raise IncorrectInput, "Invalid input: '#{str}' should be one of " +
      @hash.keys.map {|s| s.to_s}.join(',')
  end
end

#type_nameObject



89
90
91
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 89

def type_name
  return 'list'
end

#type_to_string_internal(val) ⇒ Object



102
103
104
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 102

def type_to_string_internal(val)
  return val.to_s
end