Class: MicroMicro::Parsers::ImageElementParser
- Inherits:
-
Object
- Object
- MicroMicro::Parsers::ImageElementParser
- Defined in:
- lib/micro_micro/parsers/image_element_parser.rb
Instance Attribute Summary collapse
- #value ⇒ String readonly
Instance Method Summary collapse
- #alt ⇒ String?
- #alt? ⇒ Boolean
-
#initialize(node, value) ⇒ ImageElementParser
constructor
A new instance of ImageElementParser.
- #srcset ⇒ Hash{Symbol => String}?
- #srcset? ⇒ Boolean
- #to_h ⇒ Hash{Symbol => String, Hash{Symbol => String}}
Constructor Details
permalink #initialize(node, value) ⇒ ImageElementParser
Returns a new instance of ImageElementParser.
11 12 13 14 |
# File 'lib/micro_micro/parsers/image_element_parser.rb', line 11 def initialize(node, value) @node = node @value = value end |
Instance Attribute Details
permalink #value ⇒ String (readonly)
7 8 9 |
# File 'lib/micro_micro/parsers/image_element_parser.rb', line 7 def value @value end |
Instance Method Details
permalink #alt ⇒ String?
17 18 19 |
# File 'lib/micro_micro/parsers/image_element_parser.rb', line 17 def alt @alt ||= node["alt"]&.strip end |
permalink #alt? ⇒ Boolean
22 23 24 |
# File 'lib/micro_micro/parsers/image_element_parser.rb', line 22 def alt? !alt.nil? end |
permalink #srcset ⇒ Hash{Symbol => String}?
27 28 29 |
# File 'lib/micro_micro/parsers/image_element_parser.rb', line 27 def srcset @srcset ||= image_candidates if node["srcset"] end |
permalink #srcset? ⇒ Boolean
32 33 34 |
# File 'lib/micro_micro/parsers/image_element_parser.rb', line 32 def srcset? srcset.present? end |
permalink #to_h ⇒ Hash{Symbol => String, Hash{Symbol => String}}
37 38 39 40 41 42 43 44 |
# File 'lib/micro_micro/parsers/image_element_parser.rb', line 37 def to_h hash = { value: value } hash[:srcset] = srcset if srcset? hash[:alt] = alt if alt? hash end |