Class: Epuber::NavFile::NavItem

Inherits:
Object
  • Object
show all
Defined in:
lib/epuber/from_file/nav_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(href, title) ⇒ NavItem

Returns a new instance of NavItem.

Parameters:

  • href (String)
  • title (String)


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

#childrenArray<NavItem>

Returns:



11
12
13
# File 'lib/epuber/from_file/nav_file.rb', line 11

def children
  @children
end

#hrefString

Returns:

  • (String)


7
8
9
# File 'lib/epuber/from_file/nav_file.rb', line 7

def href
  @href
end

#titleString

Returns:

  • (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?

Parameters:

  • other_href (String)
  • ignore_fragment (Boolean) (defaults to: false)

Returns:



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