class BeerDb::Model::BrewerySerializer
Attributes
brewery[R]
Public Class Methods
new( brewery )
click to toggle source
# File lib/beerdb/serializers/brewery.rb, line 7 def initialize( brewery ) @brewery = brewery end
Public Instance Methods
as_json()
click to toggle source
# File lib/beerdb/serializers/brewery.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. beers = [] brewery.beers.each do |b| beers << { key: b.key, title: b.title } end tags = [] if brewery.tags.present? brewery.tags.each { |tag| tags << tag.key } end country = { key: brewery.country.key, title: brewery.country.title } data = { key: brewery.key, title: brewery.title, synonyms: brewery.synonyms, since: brewery.since, address: brewery.address, web: brewery.web, prod: brewery.prod, # (estimated) annual production in hl e.g. 2_000 hl tags: tags, beers: beers, country: country } data end