Class: CTioga2::MetaBuilder::Types::ArrayParameter

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

Overview

An array of identical elements of type specified by :subtype. Defaults to String

Direct Known Subclasses

SetParameter

Instance Attribute Summary

Attributes inherited from CTioga2::MetaBuilder::Type

#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) ⇒ ArrayParameter

Returns a new instance of ArrayParameter.



147
148
149
150
151
152
153
154
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 147

def initialize(type)
  super
  # We make a copy for our own purposes.
  subtype = type[:subtype] || {:type => :string}
  @subtype = Type.get_type(subtype)
  @separator = /\s*,\s*/
  @separator_out = ','
end

Instance Method Details

#string_to_type_internal(str) ⇒ Object



160
161
162
163
164
165
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 160

def string_to_type_internal(str)
  ary = str.split(@separator)
  return ary.map do |a|
    @subtype.string_to_type(a)
  end
end

#type_nameObject



156
157
158
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 156

def type_name
  return 'array'
end

#type_to_string_internal(val) ⇒ Object



167
168
169
170
171
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 167

def type_to_string_internal(val)
  return val.map do |a|
    @subtype.type_to_string(a)
  end.join(@separator_out)
end