Class: BeerDb::Model::BeerSerializer
- Inherits:
-
Object
- Object
- BeerDb::Model::BeerSerializer
- Defined in:
- lib/beerdb/serializers/beer.rb
Instance Attribute Summary collapse
-
#beer ⇒ Object
readonly
Returns the value of attribute beer.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(beer) ⇒ BeerSerializer
constructor
A new instance of BeerSerializer.
Constructor Details
permalink #initialize(beer) ⇒ BeerSerializer
Returns a new instance of BeerSerializer.
7 8 9 |
# File 'lib/beerdb/serializers/beer.rb', line 7 def initialize( beer ) @beer = beer end |
Instance Attribute Details
permalink #beer ⇒ Object (readonly)
Returns the value of attribute beer.
11 12 13 |
# File 'lib/beerdb/serializers/beer.rb', line 11 def beer @beer end |
Instance Method Details
permalink #as_json ⇒ Object
[View source]
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/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 = [] if beer..present? beer..each { |tag| << 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: , brewery: brewery, country: country } data end |