Class: KjLite::Book
- Inherits:
-
Object
- Object
- KjLite::Book
- Defined in:
- lib/kjlite.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#permalink ⇒ Object
readonly
Returns the value of attribute permalink.
Instance Method Summary collapse
- #chapter(n) ⇒ Object
- #chapters(*args) ⇒ Object
-
#initialize(id, name, chapters, debug: false) ⇒ Book
constructor
A new instance of Book.
- #inspect ⇒ Object
- #to_s ⇒ Object
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
87 88 89 |
# File 'lib/kjlite.rb', line 87 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
87 88 89 |
# File 'lib/kjlite.rb', line 87 def name @name end |
#permalink ⇒ Object (readonly)
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 |
#inspect ⇒ Object
118 119 120 |
# File 'lib/kjlite.rb', line 118 def inspect() "#<KjLite::Book @name=#{@name.inspect} @chapters=#{@chapters.inspect}>" end |
#to_s ⇒ Object
122 123 124 |
# File 'lib/kjlite.rb', line 122 def to_s() @chapters end |