Class: BeerDb::Model::BrewerySerializer
- Inherits:
-
Object
- Object
- BeerDb::Model::BrewerySerializer
- Defined in:
- lib/beerdb/serializers/brewery.rb
Instance Attribute Summary collapse
-
#brewery ⇒ Object
readonly
Returns the value of attribute brewery.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(brewery) ⇒ BrewerySerializer
constructor
A new instance of BrewerySerializer.
Constructor Details
#initialize(brewery) ⇒ BrewerySerializer
Returns a new instance of BrewerySerializer.
7 8 9 |
# File 'lib/beerdb/serializers/brewery.rb', line 7 def initialize( brewery ) @brewery = brewery end |
Instance Attribute Details
#brewery ⇒ Object (readonly)
Returns the value of attribute brewery.
11 12 13 |
# File 'lib/beerdb/serializers/brewery.rb', line 11 def brewery @brewery end |
Instance Method Details
#as_json ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 = [] if brewery..present? brewery..each { |tag| << 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: , beers: beers, country: country } data end |