Class: Epuber::BookspecGenerator::TocItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(href, title = nil, landmarks = [], children = []) ⇒ TocItem

Returns a new instance of TocItem.



24
25
26
27
28
29
# File 'lib/epuber/from_file/bookspec_generator.rb', line 24

def initialize(href, title = nil, landmarks = [], children = [])
  @href = href
  @title = title
  @landmarks = landmarks
  @children = children
end

Instance Attribute Details

#childrenArray<TocItem>

Returns:



18
19
20
# File 'lib/epuber/from_file/bookspec_generator.rb', line 18

def children
  @children
end

#hrefString

Returns:

  • (String)


10
11
12
# File 'lib/epuber/from_file/bookspec_generator.rb', line 10

def href
  @href
end

#landmarksArray<Symbol>

Returns:

  • (Array<Symbol>)


22
23
24
# File 'lib/epuber/from_file/bookspec_generator.rb', line 22

def landmarks
  @landmarks
end

#titleString?

Returns:

  • (String, nil)


14
15
16
# File 'lib/epuber/from_file/bookspec_generator.rb', line 14

def title
  @title
end

Instance Method Details

#==(other) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/epuber/from_file/bookspec_generator.rb', line 35

def ==(other)
  other.is_a?(TocItem) &&
    href == other.href &&
    title == other.title &&
    landmarks == other.landmarks &&
    children == other.children
end

#attribsObject



31
32
33
# File 'lib/epuber/from_file/bookspec_generator.rb', line 31

def attribs
  [href.inspect, title&.inspect, *landmarks.map(&:inspect)].compact.join(', ')
end

#inspectObject



49
50
51
# File 'lib/epuber/from_file/bookspec_generator.rb', line 49

def inspect
  %(#<#{self.class.name} #{self}>)
end

#to_s(level = 0) ⇒ Object



43
44
45
46
47
# File 'lib/epuber/from_file/bookspec_generator.rb', line 43

def to_s(level = 0)
  indent = ' ' * level
  children_str = children.map { |c| c.to_s(level + 2) }.join("\n")
  %(#{indent}#{href.inspect} #{title.inspect} #{landmarks.inspect}\n#{children_str})
end