Class: HasHelpers::SearchPresenter::ResultPresenter

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

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

#abbreviationObject

Returns the value of attribute abbreviation.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def abbreviation
  @abbreviation
end

#details=(value) ⇒ Object (writeonly)

Sets the attribute details

Parameters:

  • value

    the value to set the attribute details to.



92
93
94
# File 'app/presenters/has_helpers/search_presenter.rb', line 92

def details=(value)
  @details = value
end

#iconObject



101
102
103
# File 'app/presenters/has_helpers/search_presenter.rb', line 101

def icon
  !photo_service && @icon # && @icon.to_icon # only return icon name
end

#idObject

Returns the value of attribute id.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def id
  @id
end

#is_headingObject

Returns the value of attribute is_heading.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def is_heading
  @is_heading
end

#klassObject

Returns the value of attribute klass.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def klass
  @klass
end

#klass_nameObject



122
123
124
# File 'app/presenters/has_helpers/search_presenter.rb', line 122

def klass_name
  @klass_name || klass.name
end

#nameObject

Returns the value of attribute name.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def name
  @name
end

#photo_infoObject

Returns the value of attribute photo_info.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def photo_info
  @photo_info
end

#screenObject

Returns the value of attribute screen.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def screen
  @screen
end

#search_submitObject

Returns the value of attribute search_submit.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def search_submit
  @search_submit
end

#serviceObject



117
118
119
120
# File 'app/presenters/has_helpers/search_presenter.rb', line 117

def service
  @service ||= "/#{ klass_name.demodulize.tableize }/#{ id }".to_service
  @service.respond_to?(:call) ? @service.call : @service
end

#show_typeObject

Returns the value of attribute show_type.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def show_type
  @show_type
end

#sub_itemObject

Returns the value of attribute sub_item.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def sub_item
  @sub_item
end

#sub_item_typeObject

Returns the value of attribute sub_item_type.



90
91
92
# File 'app/presenters/has_helpers/search_presenter.rb', line 90

def sub_item_type
  @sub_item_type
end

#typeObject



130
131
132
133
# File 'app/presenters/has_helpers/search_presenter.rb', line 130

def type
  return unless show_type && @type
  @type.demodulize.titleize
end

Instance Method Details

#base_typeObject



126
127
128
# File 'app/presenters/has_helpers/search_presenter.rb', line 126

def base_type
  @type&.safe_constantize&.base_class&.name
end

#detail_listObject



94
95
96
97
98
99
# File 'app/presenters/has_helpers/search_presenter.rb', line 94

def detail_list
  details = @details || {}
  detail_list_options = { wrapped_object: details }
  detail_list_options[:skin] = "sub-item-only" if @details.blank? || (@details && @details.all? { |_k, v| v.blank? })
  DetailListPresenter.new(detail_list_options)
end

#photo_serviceObject



105
106
107
108
109
110
111
112
113
114
115
# File 'app/presenters/has_helpers/search_presenter.rb', line 105

def photo_service
  if @photo_service_memoized
    @photo_service
  else
    @photo_service_memoized = true
    @photo_service ||= ::HasHelpers::Helpers::Application.photo_info_service(
      @photo_info,
      application: ->(resource_typish, *_) { %w[users organizations].include?(resource_typish) ? "hqadmin" : ::HasHelpers::Application.project }
    )
  end
end

#to_hObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/presenters/has_helpers/search_presenter.rb', line 135

def to_h
  {
    image_url: photo_service&.url,
    icon: icon,
    abbreviation: abbreviation,
    label: name,
    value: id,
    sub_item: sub_item,
    details: detail_list.to_h,
    type: type,
    baseType: base_type&.demodulize,
    screen: screen,
    showType: show_type
  }
end