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



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

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 )
  @props[:nested]=NestedProperty.new( self )
  
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



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

def app
  @app
end

Instance Method Details

#format(model, params) ⇒ Object

Performs actual formatting



94
95
96
# File 'lib/rubyrest/atom.rb', line 94

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

#formatter_for_model(object) ⇒ Object

Resolves the formatter to use



87
88
89
90
91
# File 'lib/rubyrest/atom.rb', line 87

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



81
82
83
84
# File 'lib/rubyrest/atom.rb', line 81

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



100
101
102
# File 'lib/rubyrest/atom.rb', line 100

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