Class: RubyRest::Atom::Formatter

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

Overview

Main Atom formatter class, composed of more specialized objects such as Feed, Entry, ServiceDocument and property formatters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Formatter

Inits all the specific formatters and property handlers used by this main formatter



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rubyrest/atom.rb', line 63

def initialize( app )
  @app = app
  
  @formatters=Hash.new
  @formatters[:feed]=FeedFormatter.new( self )
  @formatters[:entry]=EntryFormatter.new( self )
  @formatters[:service_doc]=ServiceDocFormatter.new( self )
  
  @props=Hash.new
  @props[:simple]=SimpleProperty.new( self )
  @props[:date]=DateProperty.new( self )
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



59
60
61
# File 'lib/rubyrest/atom.rb', line 59

def app
  @app
end

Instance Method Details

#format(model, params) ⇒ Object

Performs actual formatting



91
92
93
# File 'lib/rubyrest/atom.rb', line 91

def format( model, params )
  formatter_for_model( model ).format( model, params )
end

#formatter_for_model(object) ⇒ Object

Resolves the formatter to use



84
85
86
87
88
# File 'lib/rubyrest/atom.rb', line 84

def formatter_for_model( object )
  return @formatters[:feed] if @app.is_a_collection( object )
  return @formatters[:service_doc] if @app.is_a_service_doc( object )
  @formatters[:entry]
end

#formatter_for_name(name) ⇒ Object

Resolves the specified name into a formatter object



78
79
80
81
# File 'lib/rubyrest/atom.rb', line 78

def formatter_for_name( name )
  raise "No formatter was found for name #{name}" if !@formatters[name]
  return @formatters[name]
end

#property(options) ⇒ Object

Resolves the specified options into the appropiate property handler



97
98
99
# File 'lib/rubyrest/atom.rb', line 97

def property( options )
  @props[options[:type]]||@props[:simple]
end