Class: Item::FloorPlanRetriever
- Inherits:
-
BaseService
- Object
- BaseService
- Item::FloorPlanRetriever
- Defined in:
- app/services/item/floor_plan_retriever.rb
Overview
Retrieves all the room configurations vignettes associated with a particular item.
Defined Under Namespace
Classes: Result
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ FloorPlanRetriever
constructor
==== Initialization options (pass as a hash).
-
#process(product_line) ⇒ Object
Retrieves all product specifications available to a given item.
- #showcases_floor_plans(product_line) ⇒ Object
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger
Constructor Details
#initialize(options = {}) ⇒ FloorPlanRetriever
==== Initialization options (pass as a hash)
- +:max_rooms+ - At max, return only this number of floorplans
==== Examples
16 17 18 |
# File 'app/services/item/floor_plan_retriever.rb', line 16 def initialize( = {}) super end |
Instance Method Details
#process(product_line) ⇒ Object
Retrieves all product specifications available to a given item
==== Parameters
- +item+ - The item for which you want to retrieve floor plans
==== Returns
A Result object with
- +all_rooms+ - an array of rooms
30 31 32 33 34 35 36 |
# File 'app/services/item/floor_plan_retriever.rb', line 30 def process(product_line) # all_rooms = [] # all_rooms += rooms_with_floor_plans_for_item(item) # all_rooms = all_rooms.compact.uniq # all_rooms = all_rooms[0..(options[:max_rooms] - 1)] if options[:max_rooms] Result.new(all_rooms: showcases_floor_plans(product_line)) end |
#showcases_floor_plans(product_line) ⇒ Object
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 65 66 67 68 69 70 |
# File 'app/services/item/floor_plan_retriever.rb', line 38 def showcases_floor_plans(product_line) return FloorPlanDisplay.none unless product_line pl_ids = [product_line.id] pl_ids += ProductLine.ancestors_ids(product_line.id) pl_ids += ProductLine.descendants_ids(product_line.id) pl_ids = pl_ids.compact.uniq base_scope = FloorPlanDisplay .joins(floor_plan_display_room_configurations: :room_configuration) .where( 'room_configurations.heating_system_product_line_id IN (:ids) OR room_configurations.quoted_heating_system_pl_id IN (:ids)', ids: pl_ids ) .preload( :floor_plan_display_digital_assets, { floor_plan_display_digital_assets: :digital_asset }, room_configurations: [ :floor_type, :sub_floor_type, :line_items, { line_items: [:item, { item: %i[successor_item orderable_view_product_catalogs] }] } ] ) .distinct .order(created_at: :desc) scope = base_scope.published scope = base_scope unless scope.exists? # fast check before falling back to any state scope = scope.limit([:max_rooms]) if [:max_rooms] scope end |