Class: BoatSerializer
- Inherits:
-
AbstractSerializer
- Object
- AbstractSerializer
- BoatSerializer
- Defined in:
- app/serializers/boat_serializer.rb
Class Method Summary collapse
- .available_attributes ⇒ Object
- .boat_beam_metrics(boat) ⇒ Object
- .boat_beam_metrics_ft(boat) ⇒ Object
- .boat_beam_metrics_meters(boat) ⇒ Object
- .boat_contacts(boat) ⇒ Object
- .boat_draft_metrics(boat) ⇒ Object
- .boat_draft_metrics_ft(boat) ⇒ Object
- .boat_draft_metrics_meters(boat) ⇒ Object
- .boat_length_metrics(boat) ⇒ Object
- .boat_length_metrics_ft(boat) ⇒ Object
- .boat_length_metrics_meters(boat) ⇒ Object
- .boat_model(boat) ⇒ Object
- .boat_photos(boat) ⇒ Object
- .boat_type_id(boat) ⇒ Object
- .builder(boat) ⇒ Object
- .built_year(boat) ⇒ Object
- .charter_1_day_high_eur(boat) ⇒ Object
- .charter_1_day_high_rub(boat) ⇒ Object
- .charter_1_day_high_usd(boat) ⇒ Object
- .charter_1_day_low_eur(boat) ⇒ Object
- .charter_1_day_low_rub(boat) ⇒ Object
- .charter_1_day_low_usd(boat) ⇒ Object
- .charter_1_hour_high_eur(boat) ⇒ Object
- .charter_1_hour_high_rub(boat) ⇒ Object
-
.charter_1_hour_high_usd(boat) ⇒ Object
–[high]———————————————————————————————————–.
- .charter_1_hour_low_eur(boat) ⇒ Object
- .charter_1_hour_low_rub(boat) ⇒ Object
-
.charter_1_hour_low_usd(boat) ⇒ Object
–[low]———————————————————————————————————–.
- .charter_1_month_high_eur(boat) ⇒ Object
- .charter_1_month_high_rub(boat) ⇒ Object
- .charter_1_month_high_usd(boat) ⇒ Object
- .charter_1_month_low_eur(boat) ⇒ Object
- .charter_1_month_low_rub(boat) ⇒ Object
- .charter_1_month_low_usd(boat) ⇒ Object
- .charter_1_week_high_eur(boat) ⇒ Object
- .charter_1_week_high_rub(boat) ⇒ Object
- .charter_1_week_high_usd(boat) ⇒ Object
- .charter_1_week_low_eur(boat) ⇒ Object
- .charter_1_week_low_rub(boat) ⇒ Object
- .charter_1_week_low_usd(boat) ⇒ Object
- .crew_total(boat) ⇒ Object
- .default_opts ⇒ Object
- .guest_cabins(boat) ⇒ Object
- .guests_total(boat) ⇒ Object
- .id(boat) ⇒ Object
- .latitude(boat) ⇒ Object
- .location_address(boat) ⇒ Object
- .longitude(boat) ⇒ Object
- .name(boat) ⇒ Object
-
.per_season(boat) ⇒ Object
per day, per week; в день, в час, за месяц;.
-
.picture_medium_url(boat) ⇒ Object
noinspection RubyResolve.
-
.price(boat) ⇒ Object
₽ 293,885.
-
.price_discount(boat) ⇒ Object
12%.
- .refit_year(boat) ⇒ Object
- .sale_price_eur(boat) ⇒ Object
- .sale_price_rub(boat) ⇒ Object
-
.sale_price_usd(boat) ⇒ Object
–[sale]———————————————————————————————————-.
- .serialize(model, attributes: available_attributes, opts: {}) ⇒ Object
- .short_description(boat) ⇒ Object
- .state(boat) ⇒ Object
Methods inherited from AbstractSerializer
Class Method Details
.available_attributes ⇒ Object
4 5 6 7 8 9 10 11 12 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/serializers/boat_serializer.rb', line 4 def available_attributes i[ charter_1_hour_low_usd charter_1_hour_low_rub charter_1_hour_low_eur charter_1_day_low_usd charter_1_day_low_rub charter_1_day_low_eur charter_1_week_low_usd charter_1_week_low_rub charter_1_week_low_eur charter_1_month_low_usd charter_1_month_low_rub charter_1_month_low_eur charter_1_hour_high_usd charter_1_hour_high_rub charter_1_hour_high_eur charter_1_day_high_usd charter_1_day_high_rub charter_1_day_high_eur charter_1_week_high_usd charter_1_week_high_rub charter_1_week_high_eur charter_1_month_high_usd charter_1_month_high_rub charter_1_month_high_eur sale_price_usd sale_price_rub sale_price_eur id picture_medium_url name builder short_description per_season price price_discount guests_total guest_cabins crew_total built_year refit_year boat_model location_address latitude longitude boat_type_id boat_length_metrics boat_length_metrics_meters boat_length_metrics_ft boat_beam_metrics boat_beam_metrics_ft boat_beam_metrics_meters boat_draft_metrics boat_draft_metrics_ft boat_draft_metrics_meters state boat_contacts boat_photos ].freeze end |
.boat_beam_metrics(boat) ⇒ Object
193 194 195 196 |
# File 'app/serializers/boat_serializer.rb', line 193 def boat_beam_metrics(boat) value = ::Lib::Boats::Dimensions.boatbeam(boat, @opts[:uom]) { boat_beam_metrics: value } end |
.boat_beam_metrics_ft(boat) ⇒ Object
198 199 200 |
# File 'app/serializers/boat_serializer.rb', line 198 def boat_beam_metrics_ft(boat) { boat_beam_metrics_ft: boat.boat_beam_metrics_ft } end |
.boat_beam_metrics_meters(boat) ⇒ Object
202 203 204 |
# File 'app/serializers/boat_serializer.rb', line 202 def boat_beam_metrics_meters(boat) { boat_beam_metrics_meters: boat.boat_beam_metrics_meters } end |
.boat_contacts(boat) ⇒ Object
349 350 351 352 353 354 355 356 357 358 |
# File 'app/serializers/boat_serializer.rb', line 349 def boat_contacts(boat) boat_contacts = boat.users.map do |user| { id: user.id, name: user.name, email: user.email } end { boat_contacts: boat_contacts } end |
.boat_draft_metrics(boat) ⇒ Object
206 207 208 209 |
# File 'app/serializers/boat_serializer.rb', line 206 def boat_draft_metrics(boat) value = ::Lib::Boats::Dimensions.boatdraft(boat, @opts[:uom]) { boat_draft_metrics: value } end |
.boat_draft_metrics_ft(boat) ⇒ Object
211 212 213 |
# File 'app/serializers/boat_serializer.rb', line 211 def boat_draft_metrics_ft(boat) { boat_draft_metrics_ft: boat.boat_draft_metrics_ft } end |
.boat_draft_metrics_meters(boat) ⇒ Object
215 216 217 |
# File 'app/serializers/boat_serializer.rb', line 215 def boat_draft_metrics_meters(boat) { boat_draft_metrics_meters: boat.boat_draft_metrics_meters } end |
.boat_length_metrics(boat) ⇒ Object
180 181 182 183 |
# File 'app/serializers/boat_serializer.rb', line 180 def boat_length_metrics(boat) value = ::Lib::Boats::Dimensions.boatlength(boat, @opts[:uom]) { boat_length_metrics: value } end |
.boat_length_metrics_ft(boat) ⇒ Object
189 190 191 |
# File 'app/serializers/boat_serializer.rb', line 189 def boat_length_metrics_ft(boat) { boat_length_metrics_ft: boat.boat_length_metrics_ft } end |
.boat_length_metrics_meters(boat) ⇒ Object
185 186 187 |
# File 'app/serializers/boat_serializer.rb', line 185 def boat_length_metrics_meters(boat) { boat_length_metrics_meters: boat.boat_length_metrics_meters } end |
.boat_model(boat) ⇒ Object
160 161 162 |
# File 'app/serializers/boat_serializer.rb', line 160 def boat_model(boat) { boat_model: boat.boat_model } end |
.boat_photos(boat) ⇒ Object
338 339 340 341 342 343 344 345 346 347 |
# File 'app/serializers/boat_serializer.rb', line 338 def boat_photos(boat) boat_photos = boat.boat_photos.map do |boat_photo| { gallery_path: boat_photo.picture.url(:gallery), medium_path: boat_photo.picture.url(:medium), thumb_path: boat_photo.picture.url(:thumb) } end { boat_photos: boat_photos } end |
.boat_type_id(boat) ⇒ Object
176 177 178 |
# File 'app/serializers/boat_serializer.rb', line 176 def boat_type_id(boat) { boat_type_id: boat.boat_type_id } end |
.builder(boat) ⇒ Object
98 99 100 |
# File 'app/serializers/boat_serializer.rb', line 98 def builder(boat) { builder: boat.builder } end |
.built_year(boat) ⇒ Object
151 152 153 |
# File 'app/serializers/boat_serializer.rb', line 151 def built_year(boat) { built_year: boat.built_year || '' } end |
.charter_1_day_high_eur(boat) ⇒ Object
292 293 294 |
# File 'app/serializers/boat_serializer.rb', line 292 def charter_1_day_high_eur(boat) { charter_1_day_high_eur: boat.charter_1_day_high_eur || '' } end |
.charter_1_day_high_rub(boat) ⇒ Object
288 289 290 |
# File 'app/serializers/boat_serializer.rb', line 288 def charter_1_day_high_rub(boat) { charter_1_day_high_rub: boat.charter_1_day_high_rub || '' } end |
.charter_1_day_high_usd(boat) ⇒ Object
284 285 286 |
# File 'app/serializers/boat_serializer.rb', line 284 def charter_1_day_high_usd(boat) { charter_1_day_high_usd: boat.charter_1_day_high_usd || '' } end |
.charter_1_day_low_eur(boat) ⇒ Object
242 243 244 |
# File 'app/serializers/boat_serializer.rb', line 242 def charter_1_day_low_eur(boat) { charter_1_day_low_eur: boat.charter_1_day_low_eur || '' } end |
.charter_1_day_low_rub(boat) ⇒ Object
238 239 240 |
# File 'app/serializers/boat_serializer.rb', line 238 def charter_1_day_low_rub(boat) { charter_1_day_low_rub: boat.charter_1_day_low_rub || '' } end |
.charter_1_day_low_usd(boat) ⇒ Object
234 235 236 |
# File 'app/serializers/boat_serializer.rb', line 234 def charter_1_day_low_usd(boat) { charter_1_day_low_usd: boat.charter_1_day_low_usd || '' } end |
.charter_1_hour_high_eur(boat) ⇒ Object
280 281 282 |
# File 'app/serializers/boat_serializer.rb', line 280 def charter_1_hour_high_eur(boat) { charter_1_hour_high_eur: boat.charter_1_hour_high_eur || '' } end |
.charter_1_hour_high_rub(boat) ⇒ Object
276 277 278 |
# File 'app/serializers/boat_serializer.rb', line 276 def charter_1_hour_high_rub(boat) { charter_1_hour_high_rub: boat.charter_1_hour_high_rub || '' } end |
.charter_1_hour_high_usd(boat) ⇒ Object
–[high]———————————————————————————————————–
272 273 274 |
# File 'app/serializers/boat_serializer.rb', line 272 def charter_1_hour_high_usd(boat) { charter_1_hour_high_usd: boat.charter_1_hour_high_usd || '' } end |
.charter_1_hour_low_eur(boat) ⇒ Object
230 231 232 |
# File 'app/serializers/boat_serializer.rb', line 230 def charter_1_hour_low_eur(boat) { charter_1_hour_low_eur: boat.charter_1_hour_low_eur || '' } end |
.charter_1_hour_low_rub(boat) ⇒ Object
226 227 228 |
# File 'app/serializers/boat_serializer.rb', line 226 def charter_1_hour_low_rub(boat) { charter_1_hour_low_rub: boat.charter_1_hour_low_rub || '' } end |
.charter_1_hour_low_usd(boat) ⇒ Object
–[low]———————————————————————————————————–
222 223 224 |
# File 'app/serializers/boat_serializer.rb', line 222 def charter_1_hour_low_usd(boat) { charter_1_hour_low_usd: boat.charter_1_hour_low_usd || '' } end |
.charter_1_month_high_eur(boat) ⇒ Object
316 317 318 |
# File 'app/serializers/boat_serializer.rb', line 316 def charter_1_month_high_eur(boat) { charter_1_month_high_eur: boat.charter_1_month_high_eur || '' } end |
.charter_1_month_high_rub(boat) ⇒ Object
312 313 314 |
# File 'app/serializers/boat_serializer.rb', line 312 def charter_1_month_high_rub(boat) { charter_1_month_high_rub: boat.charter_1_month_high_rub || '' } end |
.charter_1_month_high_usd(boat) ⇒ Object
308 309 310 |
# File 'app/serializers/boat_serializer.rb', line 308 def charter_1_month_high_usd(boat) { charter_1_month_high_usd: boat.charter_1_month_high_usd || '' } end |
.charter_1_month_low_eur(boat) ⇒ Object
266 267 268 |
# File 'app/serializers/boat_serializer.rb', line 266 def charter_1_month_low_eur(boat) { charter_1_month_low_eur: boat.charter_1_month_low_eur || '' } end |
.charter_1_month_low_rub(boat) ⇒ Object
262 263 264 |
# File 'app/serializers/boat_serializer.rb', line 262 def charter_1_month_low_rub(boat) { charter_1_month_low_rub: boat.charter_1_month_low_rub || '' } end |
.charter_1_month_low_usd(boat) ⇒ Object
258 259 260 |
# File 'app/serializers/boat_serializer.rb', line 258 def charter_1_month_low_usd(boat) { charter_1_month_low_usd: boat.charter_1_month_low_usd || '' } end |
.charter_1_week_high_eur(boat) ⇒ Object
304 305 306 |
# File 'app/serializers/boat_serializer.rb', line 304 def charter_1_week_high_eur(boat) { charter_1_week_high_eur: boat.charter_1_week_high_eur || '' } end |
.charter_1_week_high_rub(boat) ⇒ Object
300 301 302 |
# File 'app/serializers/boat_serializer.rb', line 300 def charter_1_week_high_rub(boat) { charter_1_week_high_rub: boat.charter_1_week_high_rub || '' } end |
.charter_1_week_high_usd(boat) ⇒ Object
296 297 298 |
# File 'app/serializers/boat_serializer.rb', line 296 def charter_1_week_high_usd(boat) { charter_1_week_high_usd: boat.charter_1_week_high_usd || '' } end |
.charter_1_week_low_eur(boat) ⇒ Object
254 255 256 |
# File 'app/serializers/boat_serializer.rb', line 254 def charter_1_week_low_eur(boat) { charter_1_week_low_eur: boat.charter_1_week_low_eur || '' } end |
.charter_1_week_low_rub(boat) ⇒ Object
250 251 252 |
# File 'app/serializers/boat_serializer.rb', line 250 def charter_1_week_low_rub(boat) { charter_1_week_low_rub: boat.charter_1_week_low_rub || '' } end |
.charter_1_week_low_usd(boat) ⇒ Object
246 247 248 |
# File 'app/serializers/boat_serializer.rb', line 246 def charter_1_week_low_usd(boat) { charter_1_week_low_usd: boat.charter_1_week_low_usd || '' } end |
.crew_total(boat) ⇒ Object
147 148 149 |
# File 'app/serializers/boat_serializer.rb', line 147 def crew_total(boat) { crew_total: boat.crew_total || '' } end |
.default_opts ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'app/serializers/boat_serializer.rb', line 66 def default_opts { uom: 'ft', currency: 'USD', locale: 'en', is_for_rent: true } end |
.guest_cabins(boat) ⇒ Object
143 144 145 |
# File 'app/serializers/boat_serializer.rb', line 143 def guest_cabins(boat) { guest_cabins: boat.guest_cabins || '' } end |
.guests_total(boat) ⇒ Object
139 140 141 |
# File 'app/serializers/boat_serializer.rb', line 139 def guests_total(boat) { guests_total: boat.guests_total || '' } end |
.id(boat) ⇒ Object
79 80 81 |
# File 'app/serializers/boat_serializer.rb', line 79 def id(boat) { id: boat.id } end |
.latitude(boat) ⇒ Object
168 169 170 |
# File 'app/serializers/boat_serializer.rb', line 168 def latitude(boat) { latitude: boat.latitude } end |
.location_address(boat) ⇒ Object
164 165 166 |
# File 'app/serializers/boat_serializer.rb', line 164 def location_address(boat) { location_address: boat.location_address } end |
.longitude(boat) ⇒ Object
172 173 174 |
# File 'app/serializers/boat_serializer.rb', line 172 def longitude(boat) { longitude: boat.longitude } end |
.name(boat) ⇒ Object
94 95 96 |
# File 'app/serializers/boat_serializer.rb', line 94 def name(boat) { name: boat.name } end |
.per_season(boat) ⇒ Object
per day, per week; в день, в час, за месяц;
109 110 111 112 113 114 115 116 |
# File 'app/serializers/boat_serializer.rb', line 109 def per_season(boat) season_key = ::Lib::Boats::RentPricePerSeason.spot_rentprice_id(boat, @opts[:currency], @opts[:rent_price_id]).gsub(/_low|_high/, '') #=> charter_1_week_low, charter_1_day_high translate = I18n.t("boat.rent_price.per_#{season_key}") value = @opts[:is_for_rent] ? translate : '' { per_season: value } end |
.picture_medium_url(boat) ⇒ Object
noinspection RubyResolve
84 85 86 87 88 89 90 91 92 |
# File 'app/serializers/boat_serializer.rb', line 84 def picture_medium_url(boat) url = if boat.boat_photo.present? boat.boat_photo.picture.url(:medium).gsub('\'', ''') else '' end { picture_medium_url: url } end |
.price(boat) ⇒ Object
₽ 293,885
119 120 121 122 123 124 125 126 127 |
# File 'app/serializers/boat_serializer.rb', line 119 def price(boat) value = if @opts[:is_for_rent] ::Lib::Boats::RentPricePerSeason.price(boat, @opts[:currency], @opts[:rent_price_id]) else ::Lib::Boats::SalePrice.price(boat, @opts[:currency]) end { price: value } end |
.price_discount(boat) ⇒ Object
12%
130 131 132 133 134 135 136 137 |
# File 'app/serializers/boat_serializer.rb', line 130 def price_discount(boat) value = if @opts[:is_for_rent] ::Lib::Boats::RentPricePerSeason.price_discount(boat, @opts[:currency]) else ::Lib::Boats::SalePrice.price_discount(boat) end { price_discount: value } end |
.refit_year(boat) ⇒ Object
155 156 157 158 |
# File 'app/serializers/boat_serializer.rb', line 155 def refit_year(boat) value = boat.refit_year || '' { refit_year: value } end |
.sale_price_eur(boat) ⇒ Object
330 331 332 |
# File 'app/serializers/boat_serializer.rb', line 330 def sale_price_eur(boat) { sale_price_eur: boat.sale_price_eur || '' } end |
.sale_price_rub(boat) ⇒ Object
326 327 328 |
# File 'app/serializers/boat_serializer.rb', line 326 def sale_price_rub(boat) { sale_price_rub: boat.sale_price_rub || '' } end |
.sale_price_usd(boat) ⇒ Object
–[sale]———————————————————————————————————-
322 323 324 |
# File 'app/serializers/boat_serializer.rb', line 322 def sale_price_usd(boat) { sale_price_usd: boat.sale_price_usd || '' } end |
.serialize(model, attributes: available_attributes, opts: {}) ⇒ Object
75 76 77 |
# File 'app/serializers/boat_serializer.rb', line 75 def serialize(model, attributes: available_attributes, opts: {}) super(model, attributes: attributes, opts: default_opts.merge(opts)) end |
.short_description(boat) ⇒ Object
102 103 104 105 106 |
# File 'app/serializers/boat_serializer.rb', line 102 def short_description(boat) attr = 'short_description_%s' % @opts[:locale] value = boat.send(attr.to_sym) || '' { short_description: value } end |
.state(boat) ⇒ Object
334 335 336 |
# File 'app/serializers/boat_serializer.rb', line 334 def state(boat) { state: boat.state } end |