Class: BlgrLib::ReservationQuery
- Inherits:
-
Object
- Object
- BlgrLib::ReservationQuery
- Defined in:
- lib/blgr_lib/reservation_query.rb
Overview
about further available options
Defined Under Namespace
Classes: ConfigBuilder
Instance Method Summary collapse
-
#collections ⇒ Object
ActiveRecord data collection.
-
#initialize(blogger_id) {|config_builder| ... } ⇒ ReservationQuery
constructor
A new instance of ReservationQuery.
- #outlets_data(page = 1, per = 20) ⇒ Object
- #total_bookings ⇒ Object
- #total_covers ⇒ Object
- #total_sale ⇒ Object
Constructor Details
#initialize(blogger_id) {|config_builder| ... } ⇒ ReservationQuery
Returns a new instance of ReservationQuery.
21 22 23 24 25 26 |
# File 'lib/blgr_lib/reservation_query.rb', line 21 def initialize(blogger_id) self.blogger_id = ::Blogger.find(blogger_id) @query = ::Reservation.all yield config_builder if block_given? setup_query end |
Instance Method Details
#collections ⇒ Object
Returns ActiveRecord data collection.
41 42 43 |
# File 'lib/blgr_lib/reservation_query.rb', line 41 def collections @query.includes(:restaurant) end |
#outlets_data(page = 1, per = 20) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/blgr_lib/reservation_query.rb', line 45 def outlets_data(page= 1, per= 20) @query.joins(restaurant: :translations). where('restaurant_translations.locale = ?', 'en'). group('restaurant_translations.name', 'reservations.restaurant_id'). select('restaurant_translations.name AS outlet_name', 'COUNT(reservations.id) AS outlet_total_bookings', 'SUM(reservations.adult + reservations.kids) AS outlet_total_covers', 'SUM(reservations.total_price) AS outlet_total_sale'). page(page). per(per) end |
#total_bookings ⇒ Object
28 29 30 |
# File 'lib/blgr_lib/reservation_query.rb', line 28 def total_bookings @query.select(:id).count end |
#total_covers ⇒ Object
32 33 34 |
# File 'lib/blgr_lib/reservation_query.rb', line 32 def total_covers @query.sum('adult + kids') end |
#total_sale ⇒ Object
36 37 38 |
# File 'lib/blgr_lib/reservation_query.rb', line 36 def total_sale @query.sum('total_price') end |