Class: Epuber::NavFile::NavItem
- Inherits:
-
Object
- Object
- Epuber::NavFile::NavItem
- Defined in:
- lib/epuber/from_file/nav_file.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #find_by_href(other_href, ignore_fragment: false) ⇒ NavItem?
-
#initialize(href, title) ⇒ NavItem
constructor
A new instance of NavItem.
Constructor Details
#initialize(href, title) ⇒ NavItem
Returns a new instance of NavItem.
16 17 18 19 20 |
# File 'lib/epuber/from_file/nav_file.rb', line 16 def initialize(href, title) @href = href @title = title @children = [] end |
Instance Attribute Details
#children ⇒ Array<NavItem>
11 12 13 |
# File 'lib/epuber/from_file/nav_file.rb', line 11 def children @children end |
#href ⇒ String
7 8 9 |
# File 'lib/epuber/from_file/nav_file.rb', line 7 def href @href end |
#title ⇒ String
9 10 11 |
# File 'lib/epuber/from_file/nav_file.rb', line 9 def title @title end |
Instance Method Details
#find_by_href(other_href, ignore_fragment: false) ⇒ NavItem?
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/epuber/from_file/nav_file.rb', line 27 def find_by_href(other_href, ignore_fragment: false) if ignore_fragment other_href = other_href.split('#').first self_href = @href.split('#').first return self if self_href == other_href elsif @href == other_href return self end @children.find { |item| item.find_by_href(other_href) } end |