Class: HasHelpers::SearchPresenter::DetailListPresenter::DetailItemPresenter

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.



6
7
8
# File 'app/presenters/has_helpers/search_presenter.rb', line 6

def abbreviation
  @abbreviation
end

#format=(value) ⇒ Object (writeonly)

String value to be displayed



7
8
9
# File 'app/presenters/has_helpers/search_presenter.rb', line 7

def format=(value)
  @format = value
end

#iconsObject



32
33
34
# File 'app/presenters/has_helpers/search_presenter.rb', line 32

def icons
  [*(@icons || @icon)].lazy.map(&:to_icon)
end

#metaObject



36
37
38
# File 'app/presenters/has_helpers/search_presenter.rb', line 36

def meta
  @meta ||= {}
end

#name=(value) ⇒ Object (writeonly)

String value to be displayed



7
8
9
# File 'app/presenters/has_helpers/search_presenter.rb', line 7

def name=(value)
  @name = value
end

#skinObject

Returns the value of attribute skin.



6
7
8
# File 'app/presenters/has_helpers/search_presenter.rb', line 6

def skin
  @skin
end

#valueObject

Returns

One of the following in the given order:

  • The string explicitly set using the :name option.
  • The value passed as the :value option.
  • The name attribute of the wrapped object, if the object is present and responds to name (i.e. ActiveRecord models).
  • The wrapped_object itself, which is useful for just passing a string instead of a Hash arguments.


20
21
22
23
24
25
26
27
28
29
30
# File 'app/presenters/has_helpers/search_presenter.rb', line 20

def value
  unformatted_value = @name || @value || (wrapped_object && wrapped_object.try(:name)) || wrapped_object

  transformed_value =
    case @format
    when "date" then Chronic.parse(unformatted_value)
    else
      unformatted_value
    end
  @format ? ::HasHelpers::Helpers::Application.send("format_#{ @format }", transformed_value) : transformed_value
end

Instance Method Details

#to_hObject



40
41
42
# File 'app/presenters/has_helpers/search_presenter.rb', line 40

def to_h
  { name: value }
end