Class: QuickSearch::PinPresenter

Inherits:
BasePresenter
  • Object
show all
Defined in:
app/presenters/quick_search/pin_presenter.rb

Overview

Presenter: pin presenter.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, template, options = {}) ⇒ PinPresenter

Returns a new instance of PinPresenter.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/presenters/quick_search/pin_presenter.rb', line 30

def initialize(object, template, options = {})
  super(object, template)
  @options = options
  set_attributes
  set_result_class(object)
  @title ||= object.to_s
  if @link.blank?
    @link = if object.respond_to? :crm_link
              object.crm_link
            else
              begin
                template.polymorphic_path(object)
              rescue StandardError
                nil
              end
            end
  end
  @reference_number ||= object.try(:reference_number)
end

Instance Attribute Details

#invalidObject (readonly)

Returns the value of attribute invalid.



6
7
8
# File 'app/presenters/quick_search/pin_presenter.rb', line 6

def invalid
  @invalid
end

Returns the value of attribute link.



6
7
8
# File 'app/presenters/quick_search/pin_presenter.rb', line 6

def link
  @link
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'app/presenters/quick_search/pin_presenter.rb', line 6

def options
  @options
end

#reference_numberObject (readonly)

Returns the value of attribute reference_number.



6
7
8
# File 'app/presenters/quick_search/pin_presenter.rb', line 6

def reference_number
  @reference_number
end

#result_classObject (readonly)

Returns the value of attribute result_class.



6
7
8
# File 'app/presenters/quick_search/pin_presenter.rb', line 6

def result_class
  @result_class
end

#significant_dateObject (readonly)

Returns the value of attribute significant_date.



6
7
8
# File 'app/presenters/quick_search/pin_presenter.rb', line 6

def significant_date
  @significant_date
end

#sub_headerObject (readonly)

Returns the value of attribute sub_header.



6
7
8
# File 'app/presenters/quick_search/pin_presenter.rb', line 6

def sub_header
  @sub_header
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'app/presenters/quick_search/pin_presenter.rb', line 6

def title
  @title
end

Class Method Details

.build(object, template) ⇒ Object



26
27
28
# File 'app/presenters/quick_search/pin_presenter.rb', line 26

def self.build(object, template)
  pin_class(object).new(object, template)
end

.pin_class(r) ⇒ Object

Instantiate the appropriate search class



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/presenters/quick_search/pin_presenter.rb', line 9

def self.pin_class(r)
  klass = begin
    "QuickSearch::#{r.class.name}Presenter".constantize
  rescue StandardError
    nil
  end
  # Try a parent (e.g. Party if you are a Customer, Supplier, etc.)
  klass ||= begin
    "QuickSearch::#{r.superclass.name}Presenter".constantize
  rescue StandardError
    nil
  end
  # Default to unknownpresenter
  klass ||= "QuickSearch::UnknownPresenter".constantize
  klass
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/presenters/quick_search/pin_presenter.rb', line 60

def as_json(_options = {})
  {
    title: title,
    sub_header: sub_header,
    text_sub_header: text_sub_header,
    url: link,
    ref: try(:reference_number),
    result_class: result_class,
    type_label: type_label,
    profile_image_url: profile_image_url
  }
end

#presenting_context?(context_type, context_id) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
96
# File 'app/presenters/quick_search/pin_presenter.rb', line 92

def presenting_context?(context_type, context_id)
  return false unless context_type.present? && context_id.present?

  result.resource_type == context_type.to_s and result.resource_id == context_id.to_i
end

#profile_image_urlObject

Override in subclasses that support profile images (Customer, Contact, Supplier)



84
85
86
# File 'app/presenters/quick_search/pin_presenter.rb', line 84

def profile_image_url
  nil
end

#set_attributesObject



88
89
90
# File 'app/presenters/quick_search/pin_presenter.rb', line 88

def set_attributes
  raise "Not Implemented, you must implement this method in your subclass"
end

#set_result_class(object) ⇒ Object



50
51
52
53
54
# File 'app/presenters/quick_search/pin_presenter.rb', line 50

def set_result_class(object)
  # rubocop:disable Naming/MemoizedInstanceVariableName -- @result_class is the public attr_reader, not memoizing this method
  @result_class ||= object.class.name.tableize.singularize.to_sym
  # rubocop:enable Naming/MemoizedInstanceVariableName
end

#text_sub_headerObject

Override in subclasses that have both badges AND text info



74
75
76
# File 'app/presenters/quick_search/pin_presenter.rb', line 74

def text_sub_header
  nil
end

#to_sObject



56
57
58
# File 'app/presenters/quick_search/pin_presenter.rb', line 56

def to_s
  [reference_number, title].compact_blank.join(" \u2022 ")
end

#type_labelObject

Override in subclasses to customize the type label shown on cards



79
80
81
# File 'app/presenters/quick_search/pin_presenter.rb', line 79

def type_label
  nil
end