Class: RubyRest::Atom::SimpleProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyrest/atom.rb

Direct Known Subclasses

DateProperty

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ SimpleProperty

Returns a new instance of SimpleProperty.



105
106
107
# File 'lib/rubyrest/atom.rb', line 105

def initialize( parent )
  @parent = parent
end

Instance Method Details

#bind(object, options, value) ⇒ Object



124
125
126
# File 'lib/rubyrest/atom.rb', line 124

def bind( object, options, value  )
  object.send options[:property].to_s + "=", value
end

#format(object, options, xml) ⇒ Object



141
142
143
144
145
146
# File 'lib/rubyrest/atom.rb', line 141

def format( object, options, xml )
  return if options[:bind] == :request
  value  = value_from_model( options, object )
  new_element = xml.add_element( tag( options ) )
  new_element.add_text( value.to_s ) if value != nil 
end

#object_value(object, options) ⇒ Object



114
115
116
# File 'lib/rubyrest/atom.rb', line 114

def object_value( object, options )
  object.send options[:property]
end

#parse(object, options, xml) ⇒ Object



128
129
130
131
# File 'lib/rubyrest/atom.rb', line 128

def parse( object, options, xml )
  return if options[:bind] == :response
  bind( object, options, value_from_xml( options, xml ) )
end

#tag(options) ⇒ Object



109
110
111
112
# File 'lib/rubyrest/atom.rb', line 109

def tag( options )
  value = options[:tag]||options[:property]
  return value.to_s
end

#value_from_model(options, object) ⇒ Object



137
138
139
# File 'lib/rubyrest/atom.rb', line 137

def value_from_model( options, object )
  object_value( object, options ).to_s
end

#value_from_xml(options, xml) ⇒ Object



133
134
135
# File 'lib/rubyrest/atom.rb', line 133

def value_from_xml( options, xml )
  xml_value( xml, options )
end

#xml_value(object, options) ⇒ Object



118
119
120
121
122
# File 'lib/rubyrest/atom.rb', line 118

def xml_value( object, options )
  required = true
  required = options[:required] if options[:required] != nil
  return object.get_value( tag( options ), required )
end