Sha256: c1766cadbbfed3180f568720e58050325c53114a3da970d7c6584dcbd63c2f17

Contents?: true

Size: 915 Bytes

Versions: 4

Compression:

Stored size: 915 Bytes

Contents

module Govspeak
  class ImagePresenter
    attr_reader :image

    def initialize(image)
      @image = image
    end

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

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

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

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

    def id
      nil
    end

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
govspeak-6.5.4 lib/govspeak/presenters/image_presenter.rb
govspeak-6.5.3 lib/govspeak/presenters/image_presenter.rb
govspeak-6.5.2 lib/govspeak/presenters/image_presenter.rb
govspeak-6.5.1 lib/govspeak/presenters/image_presenter.rb