Class: Expo2

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

Defined Under Namespace

Classes: Asider, Exposer, MergeExpo, Merger, NullExpo, Pres, Recurser, SubCollection, SubExpo

Instance Method Summary collapse

Constructor Details

#initialize(prototype = nil, &block) ⇒ Expo2

Returns a new instance of Expo2.



2
3
4
5
6
7
# File 'lib/expo2.rb', line 2

def initialize(prototype=nil, &block)
  @block = block
  @prototype = prototype || NULL_EXPO
  @presenters ||= []
  self.instance_exec &@block if @block
end

Instance Method Details

#expo(object, context = {}, index = nil) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/expo2.rb', line 14

def expo(object, context={}, index=nil)
  return nil if object.nil?
  preso = @prototype.expo(object, context, index)
  @presenters.each do |pres|
    preso = deep_merge(preso, pres.go(object, context, index))
  end
  preso
end

#expo_collection(objects, context = {}) ⇒ Object



23
24
25
# File 'lib/expo2.rb', line 23

def expo_collection(objects, context={})
  objects.extend(Enumerable).map.with_index{|o, i| expo(o, context, i) }
end

#inspectObject



9
10
11
# File 'lib/expo2.rb', line 9

def inspect
  "<Expo2:#{self.object_id}, @prototype=#{@prototype.inspect}, @presenters=#{@presenters.map(&:inspect)}>"
end