Class: HakumiComponents::Image::PreviewGroup::Item
- Inherits:
-
Object
- Object
- HakumiComponents::Image::PreviewGroup::Item
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/image/preview_group/item.rb
Instance Attribute Summary collapse
-
#alt ⇒ Object
readonly
Returns the value of attribute alt.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(src:, alt: nil) ⇒ Item
constructor
A new instance of Item.
- #to_payload ⇒ Object
Constructor Details
#initialize(src:, alt: nil) ⇒ Item
Returns a new instance of Item.
11 12 13 14 |
# File 'app/components/hakumi_components/image/preview_group/item.rb', line 11 def initialize(src:, alt: nil) @src = T.let(src, String) @alt = T.let(alt, T.nilable(String)) end |
Instance Attribute Details
#alt ⇒ Object (readonly)
Returns the value of attribute alt.
20 21 22 |
# File 'app/components/hakumi_components/image/preview_group/item.rb', line 20 def alt @alt end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
17 18 19 |
# File 'app/components/hakumi_components/image/preview_group/item.rb', line 17 def src @src end |
Class Method Details
.coerce(item) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'app/components/hakumi_components/image/preview_group/item.rb', line 35 def self.coerce(item) return item if item.is_a?(HakumiComponents::Image::PreviewGroup::Item) return new(src: item) if item.is_a?(String) src = item[:src] alt = item[:alt] raise ArgumentError, "preview group item src is required" unless src.is_a?(String) && src.present? new(src: src, alt: alt.is_a?(String) ? alt : nil) end |
.coerce_all(items) ⇒ Object
28 29 30 31 32 |
# File 'app/components/hakumi_components/image/preview_group/item.rb', line 28 def self.coerce_all(items) return [] if items.nil? items.map { |item| coerce(item) } end |
Instance Method Details
#to_payload ⇒ Object
23 24 25 |
# File 'app/components/hakumi_components/image/preview_group/item.rb', line 23 def to_payload { src: @src, alt: @alt } end |