Class: CTioga2::MetaBuilder::Types::ArrayParameter
- Inherits:
-
CTioga2::MetaBuilder::Type
- Object
- CTioga2::MetaBuilder::Type
- CTioga2::MetaBuilder::Types::ArrayParameter
- 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
Instance Attribute Summary
Attributes inherited from CTioga2::MetaBuilder::Type
#namespace, #namespace_lookup, #passthrough, #re_shortcuts, #shortcuts, #type
Instance Method Summary collapse
-
#initialize(type) ⇒ ArrayParameter
constructor
A new instance of ArrayParameter.
- #string_to_type_internal(str) ⇒ Object
- #type_name ⇒ Object
- #type_to_string_internal(val) ⇒ Object
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.
144 145 146 147 148 149 150 151 152 |
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 144 def initialize(type) super # We make a copy for our own purposes. subtype = type[:subtype] || {:type => :string} @subtype = Type.get_type(subtype) @separator = type[:separator] || /\s*,\s*/ @alternative_separator = type[:alternative_separator] || nil @separator_out = type[:separator_out] || ',' end |
Instance Method Details
#string_to_type_internal(str) ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 158 def string_to_type_internal(str) if @alternative_separator && str =~ @alternative_separator ary = str.split(@alternative_separator) else ary = str.split(@separator) end return ary.map do |a| @subtype.string_to_type(a) end end |
#type_name ⇒ Object
154 155 156 |
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 154 def type_name return 'array' end |
#type_to_string_internal(val) ⇒ Object
169 170 171 172 173 174 |
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 169 def type_to_string_internal(val) return val.map do |a| @subtype.type_to_string(a) # Won't alway work ! end.join(@separator_out) end |