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

#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.



115
116
117
118
119
120
121
122
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 115

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



128
129
130
131
132
133
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 128

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

#type_nameObject



124
125
126
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 124

def type_name
  return 'array'
end

#type_to_string_internal(val) ⇒ Object



135
136
137
138
139
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 135

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