Class: OpenStax::Cnx::V1::Figure
- Defined in:
- lib/openstax/cnx/v1/figure.rb
Constant Summary collapse
- MATCH_FIGURE =
"//*[contains(@class, 'os-figure')]"- MATCH_FIGURE_CAPTION =
".//*[contains(@class, 'os-caption')]"- MATCH_FIGURE_ALT_TEXT =
'.//*[@alt]'- MATCH_FIGURE_DATA_ALT_TEXT =
'.//*[@data-alt]'- MATCH_FIGURE_ELEM =
'.//figure'
Instance Attribute Summary
Attributes inherited from Element
Class Method Summary collapse
Instance Method Summary collapse
- #alt_text ⇒ Object
- #caption ⇒ Object
- #id ⇒ Object
-
#initialize(node:) ⇒ Figure
constructor
A new instance of Figure.
Constructor Details
#initialize(node:) ⇒ Figure
Returns a new instance of Figure.
10 11 12 |
# File 'lib/openstax/cnx/v1/figure.rb', line 10 def initialize(node:) super end |
Class Method Details
.matcher ⇒ Object
27 28 29 |
# File 'lib/openstax/cnx/v1/figure.rb', line 27 def self.matcher MATCH_FIGURE end |
.matches?(node) ⇒ Boolean
31 32 33 |
# File 'lib/openstax/cnx/v1/figure.rb', line 31 def self.matches?(node) node.matches?(MATCH_FIGURE) end |
Instance Method Details
#alt_text ⇒ Object
22 23 24 25 |
# File 'lib/openstax/cnx/v1/figure.rb', line 22 def alt_text node.at_xpath(MATCH_FIGURE_ALT_TEXT).try(:attr, 'alt') || node.at_xpath(MATCH_FIGURE_DATA_ALT_TEXT).try(:attr, 'data-alt') end |
#caption ⇒ Object
14 15 16 |
# File 'lib/openstax/cnx/v1/figure.rb', line 14 def caption node.at_xpath(MATCH_FIGURE_CAPTION).try(:text) end |
#id ⇒ Object
18 19 20 |
# File 'lib/openstax/cnx/v1/figure.rb', line 18 def id node.at_xpath(MATCH_FIGURE_ELEM).attr('id') end |