Class: CafeCar::StringPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/cafe_car/string_presenter.rb

Instance Method Summary collapse

Instance Method Details

#titleObject



3
# File 'app/presenters/cafe_car/string_presenter.rb', line 3

def title = to_s

#to_sObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/presenters/cafe_car/string_presenter.rb', line 5

def to_s
  length = @options[:truncate]
  txt    = object
  txt    = @template.truncate(txt, length:) if length

  case object
  when %r{^https?://.+\.(png|jpe?g|svg)$}
    @template.image_tag object, style: "width: 1em"
  when %r{^https?://}
    link_to(txt, object, target: "_blank", rel: "noopener")
  else
    txt
  end
end