class Terrazine::Presenter
convinient for API presenter
Public Class Methods
present(result, options)
click to toggle source
TODO: delete fields
# File lib/terrazine/presenter.rb, line 6 def present(result, options) if options[:array] || result.count > 1 return [] if result.count.zero? result.map { |i| present_row i, options[:structure] } else return nil if result.count.zero? present_row result, options[:structure] end end
present_row(row, structure)
click to toggle source
# File lib/terrazine/presenter.rb, line 16 def present_row(row, structure) hash = row.to_h if structure.present? structure.each do |k, v| hash[k] = present_value(row, v) end end hash.compact end
present_value(row, modifier)
click to toggle source
TODO!!!
# File lib/terrazine/presenter.rb, line 27 def present_value(row, modifier) case modifier when Result modifier.present when Proc present_value row, modifier.call(row) else modifier end end