Class: Peanuts::Converter::Convert_list

Inherits:
Peanuts::Converter show all
Defined in:
lib/peanuts/converters.rb

Overview

An XSD whitespace-separated list.

Specifier

:list, :item_type => simple type specifier

Alternative specifier

[simple type specifier]

Ruby type

Array of simple type

Options

All options will be passed to the underlying type converter.

Instance Method Summary collapse

Methods inherited from Peanuts::Converter

create, create!, lookup, lookup!

Constructor Details

#initialize(options) ⇒ Convert_list

Returns a new instance of Convert_list.



219
220
221
222
# File 'lib/peanuts/converters.rb', line 219

def initialize(options)
  @item_type = options[:item_type] || :string
  @item_converter = Converter.create!(@item_type, options)
end

Instance Method Details

#from_xml(string) ⇒ Object



228
229
230
# File 'lib/peanuts/converters.rb', line 228

def from_xml(string)
  string && string.split.map! {|x| @item_converter.from_xml(x)}
end

#to_xml(items) ⇒ Object



224
225
226
# File 'lib/peanuts/converters.rb', line 224

def to_xml(items)
  items && items.map {|x| @item_converter.to_xml(x) } * ' '
end