Class: ArticleJSON::Elements::Image
- Defined in:
- lib/article_json/elements/image.rb
Instance Attribute Summary collapse
-
#alt ⇒ Object
readonly
Returns the value of attribute alt.
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#float ⇒ Object
readonly
Returns the value of attribute float.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#source_url ⇒ Object
readonly
Returns the value of attribute source_url.
Attributes inherited from Base
Class Method Summary collapse
-
.parse_hash(hash) ⇒ ArticleJSON::Elements::Image
Create a image element from Hash.
Instance Method Summary collapse
-
#initialize(source_url:, caption:, float: nil, href: nil, alt: nil) ⇒ Image
constructor
A new instance of Image.
-
#to_h ⇒ Hash
Hash representation of this image element.
Methods inherited from Base
Constructor Details
#initialize(source_url:, caption:, float: nil, href: nil, alt: nil) ⇒ Image
Returns a new instance of Image.
11 12 13 14 15 16 17 18 |
# File 'lib/article_json/elements/image.rb', line 11 def initialize(source_url:, caption:, float: nil, href: nil, alt: nil) @type = :image @source_url = source_url @caption = @float = float @href = href @alt = alt end |
Instance Attribute Details
#alt ⇒ Object (readonly)
Returns the value of attribute alt.
4 5 6 |
# File 'lib/article_json/elements/image.rb', line 4 def alt @alt end |
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
4 5 6 |
# File 'lib/article_json/elements/image.rb', line 4 def @caption end |
#float ⇒ Object (readonly)
Returns the value of attribute float.
4 5 6 |
# File 'lib/article_json/elements/image.rb', line 4 def float @float end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
4 5 6 |
# File 'lib/article_json/elements/image.rb', line 4 def href @href end |
#source_url ⇒ Object (readonly)
Returns the value of attribute source_url.
4 5 6 |
# File 'lib/article_json/elements/image.rb', line 4 def source_url @source_url end |
Class Method Details
.parse_hash(hash) ⇒ ArticleJSON::Elements::Image
Create a image element from Hash
36 37 38 39 40 41 42 43 44 |
# File 'lib/article_json/elements/image.rb', line 36 def parse_hash(hash) new( source_url: hash[:source_url], caption: parse_hash_list(hash[:caption]), float: hash[:float]&.to_sym, href: hash[:href], alt: hash[:alt] ) end |
Instance Method Details
#to_h ⇒ Hash
Hash representation of this image element
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/article_json/elements/image.rb', line 22 def to_h { type: type, source_url: source_url, float: float, caption: .map(&:to_h), href: href, alt: alt, } end |