Class: HasHelpers::SearchPresenter::DetailListPresenter
- Inherits:
-
BasePresenter
- Object
- BasePresenter
- HasHelpers::SearchPresenter::DetailListPresenter
- Defined in:
- app/presenters/has_helpers/search_presenter.rb
Defined Under Namespace
Classes: DetailItemPresenter
Instance Attribute Summary collapse
-
#skin ⇒ Object
Returns the value of attribute skin.
Attributes inherited from BasePresenter
Instance Method Summary collapse
Methods inherited from BasePresenter
#==, #error_on, #initialize, wrap, wrap_with_options
Methods included from Attributes
Constructor Details
This class inherits a constructor from HasHelpers::BasePresenter
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class HasHelpers::BasePresenter
Instance Attribute Details
#skin ⇒ Object
Returns the value of attribute skin.
45 46 47 |
# File 'app/presenters/has_helpers/search_presenter.rb', line 45 def skin @skin end |
Instance Method Details
#details ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/presenters/has_helpers/search_presenter.rb', line 47 def details (wrapped_object || []).lazy.select do |_heading, *items| items.any? end.map do |heading, *items| detail_items = ( case items.first when Hash then [items.first] else [*[*items].first] # [*[*items].first] handles *items catching either a single record instance or an array of hashes. end ).map do |detail_args| unless detail_args.has_key?("format") # Automatically select format format = heading.to_s.singularize.underscore if ::HasHelpers::Helpers::Application.respond_to?("format_#{ format }") detail_args["format"] = format end end DetailItemPresenter.new(detail_args) end [ heading, detail_items, detail_items.all? { |item| item.skin && item.skin.include?("sub-item") } ? "sub-item-group" : nil ] end end |
#to_h ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'app/presenters/has_helpers/search_presenter.rb', line 77 def to_h details.map do |heading, detail_items, skin| { id: detail_items.hash, heading: heading, detail_items: detail_items, skin: skin } end end |