Sha256: cca801e4d2f174fcce83bd8e92adb98770203682d52514f3873e930fd664125e
Contents?: true
Size: 896 Bytes
Versions: 36
Compression:
Stored size: 896 Bytes
Contents
require 'ostruct' class ThemePresentation def self.wrap(data, *presenters) normalized = normalize(data) presenters = normalize_presenters(presenters) wrapped_data = presenters.inject(normalized) do |wrapped, presenter| presenter.new(wrapped) end class << wrapped_data attr_accessor :wrapped_by end wrapped_data.wrapped_by = presenters wrapped_data end def self.wrap_collection(collection, *presenters) collection.collect { |item| wrap(item, *presenters) } end private def self.normalize(data) if data.is_a? Hash hash = {} data.each { |key, value| hash[key] = normalize value } OpenStruct.new hash elsif data.is_a? Array data.collect { |datum| normalize datum } else data end end def self.normalize_presenters(presenters) presenters.reject!(&:nil?) presenters end end
Version data entries
36 entries across 36 versions & 1 rubygems