Class: Peanuts::Mappings::MemberMapping

Inherits:
Peanuts::Mapping show all
Defined in:
lib/peanuts/mappings.rb

Direct Known Subclasses

Attribute, Element, ElementValue, ElementValues, Elements

Instance Attribute Summary collapse

Attributes inherited from Peanuts::Mapping

#options, #prefix, #xmlname, #xmlns

Instance Method Summary collapse

Methods inherited from Peanuts::Mapping

#node_type, node_type

Constructor Details

#initialize(name, type, options) ⇒ MemberMapping

Returns a new instance of MemberMapping.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/peanuts/mappings.rb', line 36

def initialize(name, type, options)
  super(options.delete(:xmlname) || name, options)
  case type
  when Array
    raise ArgumentError, "invalid value for type: #{type.inspect}" if type.length != 1
    options[:item_type] = type.first
    @converter = Converter.create!(:list, options)
  when Class
    options[:object_type] = type
  else
    @converter = Converter.create!(type, options)
  end
  @name, @setter, @type = name.to_sym, :"#{name}=", type
end

Instance Attribute Details

#converterObject (readonly)

Returns the value of attribute converter.



34
35
36
# File 'lib/peanuts/mappings.rb', line 34

def converter
  @converter
end

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/peanuts/mappings.rb', line 34

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



34
35
36
# File 'lib/peanuts/mappings.rb', line 34

def type
  @type
end

Instance Method Details

#clear(nut) ⇒ Object



59
60
61
# File 'lib/peanuts/mappings.rb', line 59

def clear(nut)
  set(nut, nil)
end

#restore(nut, reader) ⇒ Object



55
56
57
# File 'lib/peanuts/mappings.rb', line 55

def restore(nut, reader)
  set(nut, restore_value(reader, get(nut)))
end

#save(nut, writer) ⇒ Object



51
52
53
# File 'lib/peanuts/mappings.rb', line 51

def save(nut, writer)
  save_value(writer, get(nut))
end