Class: BoatPriceSerializer

Inherits:
AbstractSerializer show all
Defined in:
app/serializers/boat_price_serializer.rb

Class Method Summary collapse

Methods inherited from AbstractSerializer

opts, serialize

Class Method Details

.available_attributesObject



4
5
6
# File 'app/serializers/boat_price_serializer.rb', line 4

def available_attributes
  %i[season uom duration currency value discount]
end

.currency(boat_price) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'app/serializers/boat_price_serializer.rb', line 31

def currency(boat_price)
  bp = ::Dicts::Currency.find(boat_price.currency_id)

  {
      currency: {
          id:     bp.id,
          index:  bp.index,
          symbol: bp.symbol
      }
  }
end

.discount(boat_price) ⇒ Object



48
49
50
# File 'app/serializers/boat_price_serializer.rb', line 48

def discount(boat_price)
  { discount: sprintf('%.2f', boat_price.discount) }
end

.duration(boat_price) ⇒ Object



27
28
29
# File 'app/serializers/boat_price_serializer.rb', line 27

def duration(boat_price)
  { duration: boat_price.duration }
end

.is_orig(boat_price) ⇒ Object

TODO

прояснить надобность, проработать тему



53
54
55
# File 'app/serializers/boat_price_serializer.rb', line 53

def is_orig(boat_price)
  { is_orig: boat_price.is_orig }
end

.season(boat_price) ⇒ Object



8
9
10
11
12
13
14
15
# File 'app/serializers/boat_price_serializer.rb', line 8

def season(boat_price)
  {
      season: {
          id:     boat_price.season_id,
          index:  ::Dicts::CharterSeason.find(boat_price.season_id).index
      }
  }
end

.uom(boat_price) ⇒ Object

час, день, неделя, месяц



18
19
20
21
22
23
24
25
# File 'app/serializers/boat_price_serializer.rb', line 18

def uom(boat_price)
  {
      uom: {
          id:    boat_price.uom_id,
          index: ::Dicts::CharterUom.find(boat_price.uom_id).index
      }
  }
end

.value(boat_price) ⇒ Object

цена за указанный период



44
45
46
# File 'app/serializers/boat_price_serializer.rb', line 44

def value(boat_price)
  { value: sprintf('%d', boat_price.value) }
end