Class: Peanuts::Converter::Convert_list

Inherits:
Object
  • Object
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

Constructor Details

#initialize(options) ⇒ Convert_list

Returns a new instance of Convert_list.



210
211
212
213
# File 'lib/peanuts/converters.rb', line 210

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

Instance Method Details

#from_xml(string) ⇒ Object



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

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

#to_xml(items) ⇒ Object



215
216
217
# File 'lib/peanuts/converters.rb', line 215

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