Class: KjLite::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/kjlite.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, chapters, debug: false) ⇒ Book

Returns a new instance of Book.



89
90
91
92
93
94
95
96
97
98
# File 'lib/kjlite.rb', line 89

def initialize(id, name, chapters, debug: false)

  @id, @name, @debug = id, name, debug
  @permalink = name.downcase.gsub(/\s/,'-')
  puts 'chapters.length : ' + chapters.length.inspect if @debug
  @chapters = chapters.map.with_index do |x,i|
    Chapter.new x, i+1, id, name, debug: @debug
  end

end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



87
88
89
# File 'lib/kjlite.rb', line 87

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



87
88
89
# File 'lib/kjlite.rb', line 87

def name
  @name
end

Returns the value of attribute permalink.



87
88
89
# File 'lib/kjlite.rb', line 87

def permalink
  @permalink
end

Instance Method Details

#chapter(n) ⇒ Object



100
101
102
# File 'lib/kjlite.rb', line 100

def chapter(n)
  chapters n
end

#chapters(*args) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/kjlite.rb', line 104

def chapters(*args)

  puts 'args: ' + args.inspect if @debug

  if args.empty? then
    return @chapters
  elsif args.length < 2
    @chapters[args.first.to_i-1]
  else
    args.flatten.map {|n| @chapters[n-1] }.compact
  end

end

#inspectObject



118
119
120
# File 'lib/kjlite.rb', line 118

def inspect()
  "#<KjLite::Book @name=#{@name.inspect} @chapters=#{@chapters.inspect}>"
end

#to_sObject



122
123
124
# File 'lib/kjlite.rb', line 122

def to_s()
  @chapters
end