class BeerDb::Model::BeerSerializer
Attributes
beer[R]
Public Class Methods
new( beer )
click to toggle source
# File lib/beerdb/serializers/beer.rb, line 7 def initialize( beer ) @beer = beer end
Public Instance Methods
as_json()
click to toggle source
# File lib/beerdb/serializers/beer.rb, line 13 def as_json ## note: as_json returns record as a hash ## note: NOT yet converted with to_json or JSON.pretty_generate etc. brewery = {} if beer.brewery.present? brewery = { key: beer.brewery.key, title: beer.brewery.title } end tags = [] if beer.tags.present? beer.tags.each { |tag| tags << tag.key } end country = { key: beer.country.key, title: beer.country.title } data = { key: beer.key, title: beer.title, synonyms: beer.synonyms, abv: beer.abv, srm: beer.srm, og: beer.og, tags: tags, brewery: brewery, country: country } data end