Class: Www::FloorPlanDisplayPresenter
Overview
Presenter: floor plan display presenter.
Instance Attribute Summary
#current_account, #options, #url_helper
Instance Method Summary
collapse
#can?, #capture, #concat, #content_tag, #fa_icon, #h, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u
Constructor Details
Returns a new instance of FloorPlanDisplayPresenter.
4
5
6
7
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 4
def initialize(floor_plan_display, view_context)
@floor_plan_display = floor_plan_display
@view_context = view_context
end
|
Instance Method Details
#breadcrumb_items ⇒ Object
101
102
103
104
105
106
107
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 101
def breadcrumb_items
[
{ name: 'Home', url: @view_context.root_path },
{ name: 'Floor Plan Displays', url: @view_context.floor_plan_displays_path },
{ name: @floor_plan_display.name, url: @view_context.floor_plan_display_path(@floor_plan_display) }
]
end
|
#display_description ⇒ Object
21
22
23
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 21
def display_description
@floor_plan_display.description.presence || 'No description available.'
end
|
#display_name ⇒ Object
17
18
19
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 17
def display_name
@floor_plan_display.name
end
|
#image_summary ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 37
def image_summary
count = @floor_plan_display.images.count
case count
when 0
'No images available'
when 1
'1 image'
else
"#{count} images"
end
end
|
#images_with_details ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 86
def images_with_details
@floor_plan_display.images.order(:position).map do |image|
{
id: image.id,
title: image.title,
url: image.attachment.url,
size: image.attachment_size,
size_display: @view_context.number_to_human_size(image.attachment_size),
reference_number: image.reference_number,
from_room_config: image.tags&.include?('room-configuration'),
position: image.position
}
end
end
|
#main_image_url ⇒ Object
68
69
70
71
72
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 68
def main_image_url
return nil if @floor_plan_display.main_image.blank?
@floor_plan_display.main_image.attachment.url
end
|
13
14
15
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 13
def meta_description
@floor_plan_display.seo_description.presence || truncate_description(@floor_plan_display.description)
end
|
#operating_cost_display ⇒ Object
49
50
51
52
53
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 49
def operating_cost_display
return 'Cost not available' if @floor_plan_display.total_cost_to_operate.zero?
"$#{@view_context.number_with_precision(@floor_plan_display.total_cost_to_operate, precision: 2)}"
end
|
#room_configuration_summary ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 25
def room_configuration_summary
count = @floor_plan_display.room_configurations.count
case count
when 0
'No room configurations'
when 1
'1 room configuration'
else
"#{count} room configurations"
end
end
|
#room_configurations_with_details ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 74
def room_configurations_with_details
@floor_plan_display.floor_plan_display_room_configurations.includes(:room_configuration).map do |fpdr|
{
room_name: fpdr.room_name,
room_description: fpdr.room_description,
cost_to_operate: fpdr.cost_to_operate,
reference_number: fpdr.room_configuration.reference_number,
operating_cost_display: "$#{@view_context.number_with_precision(fpdr.cost_to_operate, precision: 2)}"
}
end
end
|
#social_share_data ⇒ Object
109
110
111
112
113
114
115
116
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 109
def social_share_data
{
title: title,
description: meta_description,
image: main_image_url,
url: @view_context.floor_plan_display_url(@floor_plan_display)
}
end
|
#state_display ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 55
def state_display
case @floor_plan_display.state
when 'published'
'Published'
when 'draft'
'Draft'
when 'archived'
'Archived'
else
@floor_plan_display.state.humanize
end
end
|
#title ⇒ Object
9
10
11
|
# File 'app/presenters/www/floor_plan_display_presenter.rb', line 9
def title
@floor_plan_display.seo_title.presence || @floor_plan_display.name
end
|