Class: Govspeak::ImagePresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/govspeak/presenters/image_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ ImagePresenter

Returns a new instance of ImagePresenter.



5
6
7
# File 'lib/govspeak/presenters/image_presenter.rb', line 5

def initialize(image)
  @image = image
end

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



3
4
5
# File 'lib/govspeak/presenters/image_presenter.rb', line 3

def image
  @image
end

Instance Method Details

#alt_textObject



13
14
15
# File 'lib/govspeak/presenters/image_presenter.rb', line 13

def alt_text
  image.respond_to?(:alt_text) ? image.alt_text : image[:alt_text]
end

#captionObject



17
18
19
# File 'lib/govspeak/presenters/image_presenter.rb', line 17

def caption
  (image.respond_to?(:caption) ? image.caption : image[:caption]).to_s.strip.presence
end

#creditObject



21
22
23
# File 'lib/govspeak/presenters/image_presenter.rb', line 21

def credit
  (image.respond_to?(:credit) ? image.credit : image[:credit]).to_s.strip.presence
end

#figcaption?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/govspeak/presenters/image_presenter.rb', line 29

def figcaption?
  caption.present? || credit.present?
end

#figcaption_htmlObject



33
34
35
36
37
38
39
40
# File 'lib/govspeak/presenters/image_presenter.rb', line 33

def figcaption_html
  lines = []
  lines << "<figcaption>"
  lines << %(<p>#{caption}</p>) if caption.present?
  lines << %(<p>#{I18n.t('govspeak.image.figure.credit', credit:)}</p>) if credit.present?
  lines << "</figcaption>"
  lines.join
end

#idObject



25
26
27
# File 'lib/govspeak/presenters/image_presenter.rb', line 25

def id
  nil
end

#urlObject



9
10
11
# File 'lib/govspeak/presenters/image_presenter.rb', line 9

def url
  image.respond_to?(:url) ? image.url : image[:url]
end