Class: Govspeak::ImagePresenter
- Inherits:
-
Object
- Object
- Govspeak::ImagePresenter
- Defined in:
- lib/govspeak/presenters/image_presenter.rb
Instance Attribute Summary collapse
-
#image ⇒ Object
readonly
Returns the value of attribute image.
Instance Method Summary collapse
- #alt_text ⇒ Object
- #caption ⇒ Object
- #credit ⇒ Object
- #figcaption? ⇒ Boolean
- #figcaption_html ⇒ Object
- #id ⇒ Object
-
#initialize(image) ⇒ ImagePresenter
constructor
A new instance of ImagePresenter.
- #url ⇒ Object
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
#image ⇒ Object (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_text ⇒ Object
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 |
#caption ⇒ Object
17 18 19 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 17 def (image.respond_to?(:caption) ? image. : image[:caption]).to_s.strip.presence end |
#credit ⇒ Object
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
29 30 31 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 29 def .present? || credit.present? end |
#figcaption_html ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 33 def lines = [] lines << "<figcaption>" lines << %(<p>#{}</p>) if .present? lines << %(<p>#{I18n.t('govspeak.image.figure.credit', credit:)}</p>) if credit.present? lines << "</figcaption>" lines.join end |
#id ⇒ Object
25 26 27 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 25 def id nil end |
#url ⇒ Object
9 10 11 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 9 def url image.respond_to?(:url) ? image.url : image[:url] end |