Class: Kitchen::CompositePageElement
- Inherits:
-
ElementBase
- Object
- ElementBase
- Kitchen::CompositePageElement
- Defined in:
- lib/kitchen/composite_page_element.rb
Overview
An element for a composite page
Instance Attribute Summary
Attributes inherited from ElementBase
#ancestors, #document, #enumerator_class, #search_query_that_found_me, #short_type
Class Method Summary collapse
-
.short_type ⇒ Symbol
Returns the short type.
Instance Method Summary collapse
-
#initialize(node:, document: nil) ⇒ CompositePageElement
constructor
Creates a new
CompositePageElement
. -
#is_citation_reference? ⇒ Boolean
Returns true if this page is a book citation reference.
-
#is_index? ⇒ Boolean
Returns true if this page is a book index.
-
#is_index_of_type? ⇒ Boolean
Returns true if this page is a book index of type.
-
#is_section_reference? ⇒ Boolean
Returns true if this page is a book section reference.
-
#metadata ⇒ Element
Returns the metadata element.
-
#title(reload: false) ⇒ Element
Returns the title element (the one in the immediate children, not the one in the metadata).
Methods inherited from ElementBase
#[], #[]=, #add_ancestor, #add_ancestors, #add_class, #add_platform_media, #ancestor, #ancestor_elements, #append, #as_enumerator, #children, #classes, #clone, #config, #contains?, #contains_blockish?, #content, #copy, #count_in, #custom_target_label_for_modules, #cut, #data_sm, #data_sm_formatted, #data_source, #data_type, descendant, descendant!, #element_children, #first, #first!, #has_ancestor?, #has_class?, #href, #href=, #id, #id=, #inner_html=, #inspect, #is?, is_the_element_class_for?, #key?, #mark_as_current_location!, #name, #name=, #pages, #pantry, #parent, #paste, #path, #preceded_by_text, #prepend, #previous, #raw, #raw_search, #remember_that_a_sub_element_was_counted, #remove_attribute, #remove_class, #replace_children, #rex_link, #say_source_or_nil, #search, #search_history, #selectors, #set, #sub_header_name, #target_label, #text, #to_html, #to_s, #to_xhtml, #to_xml, #trash, #uncount, #wrap, #wrap_children
Methods included from Mixins::BlockErrorIf
Constructor Details
#initialize(node:, document: nil) ⇒ CompositePageElement
Creates a new CompositePageElement
13 14 15 16 17 |
# File 'lib/kitchen/composite_page_element.rb', line 13 def initialize(node:, document: nil) super(node: node, document: document, enumerator_class: CompositePageElementEnumerator) end |
Class Method Details
.short_type ⇒ Symbol
Returns the short type
22 23 24 |
# File 'lib/kitchen/composite_page_element.rb', line 22 def self.short_type :composite_page end |
Instance Method Details
#is_citation_reference? ⇒ Boolean
Returns true if this page is a book citation reference
82 83 84 |
# File 'lib/kitchen/composite_page_element.rb', line 82 def is_citation_reference? has_class?('os-eob os-reference-container') end |
#is_index? ⇒ Boolean
Returns true if this page is a book index
57 58 59 |
# File 'lib/kitchen/composite_page_element.rb', line 57 def is_index? has_class?('os-index-container') end |
#is_index_of_type? ⇒ Boolean
Returns true if this page is a book index of type
65 66 67 |
# File 'lib/kitchen/composite_page_element.rb', line 65 def is_index_of_type? (self[:class] || '').match?(/os-index-.+-container/) end |
#is_section_reference? ⇒ Boolean
Returns true if this page is a book section reference
90 91 92 |
# File 'lib/kitchen/composite_page_element.rb', line 90 def is_section_reference? has_class?('os-eob os-references-container') end |
#metadata ⇒ Element
Returns the metadata element.
49 50 51 |
# File 'lib/kitchen/composite_page_element.rb', line 49 def first!("div[data-type='metadata']") end |
#title(reload: false) ⇒ Element
Returns the title element (the one in the immediate children, not the one in the metadata)
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kitchen/composite_page_element.rb', line 31 def title(reload: false) @title ||= begin selector = 'h3[data-type="title"], h2[data-type="document-title"],' \ 'h1[data-type="document-title"]' search(selector, reload: reload).map do |title| next if title.parent[:'data-type'] == 'metadata' return title end raise "Title not found for composite page id=#{id}" end end |