Class: HasHelpers::SearchPresenter::DetailListPresenter

Inherits:
BasePresenter
  • Object
show all
Defined in:
app/presenters/has_helpers/search_presenter.rb

Defined Under Namespace

Classes: DetailItemPresenter

Instance Attribute Summary collapse

Attributes inherited from BasePresenter

#errors, #wrapped_object

Instance Method Summary collapse

Methods inherited from BasePresenter

#==, #error_on, #initialize, wrap, wrap_with_options

Methods included from Attributes

included

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

#skinObject

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

#detailsObject



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_hObject



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