Class: Kitchen::UnitElement
- Inherits:
-
ElementBase
- Object
- ElementBase
- Kitchen::UnitElement
- Defined in:
- lib/kitchen/unit_element.rb
Overview
An element for a unit
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) ⇒ UnitElement
constructor
Creates a new
UnitElement
. -
#title ⇒ Element
Get the title in the immediate children, not the one in the metadata.
-
#title_text ⇒ String
Returns the title’s text regardless of whether the title has been baked.
Methods inherited from ElementBase
#[], #[]=, #add_ancestor, #add_ancestors, #add_class, #ancestor, #ancestor_elements, #append, #as_enumerator, #children, #classes, #clone, #config, #contains?, #content, #copied_id, #copy, #count_in, #cut, #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, #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) ⇒ UnitElement
Creates a new UnitElement
13 14 15 16 17 |
# File 'lib/kitchen/unit_element.rb', line 13 def initialize(node:, document: nil) super(node: node, document: document, enumerator_class: UnitElementEnumerator) end |
Class Method Details
.short_type ⇒ Symbol
Returns the short type
22 23 24 |
# File 'lib/kitchen/unit_element.rb', line 22 def self.short_type :unit end |
Instance Method Details
#title ⇒ Element
Get the title in the immediate children, not the one in the metadata. Could use CSS of “:not() >
[data-type='document-title'], [data-type='document-title']"
but xpath is shorter
32 33 34 |
# File 'lib/kitchen/unit_element.rb', line 32 def title first!("./*[@data-type = 'document-title']") end |
#title_text ⇒ String
Returns the title’s text regardless of whether the title has been baked
40 41 42 |
# File 'lib/kitchen/unit_element.rb', line 40 def title_text title.children.one? ? title.text : title.first('.os-text').text end |