Skip to content

Instantly share code, notes, and snippets.

@arn-e
Created October 11, 2012 03:11
Show Gist options
  • Save arn-e/3869939 to your computer and use it in GitHub Desktop.
Save arn-e/3869939 to your computer and use it in GitHub Desktop.
toc
#Getting Started,1
#Numbers,9
#Letters,13
#Variables and Assignment,21
#Mixing It Up,25
#More About Methods,33
require 'csv'
class TableOfContents
def initialize
@toc_header = "Table of Contents"
@toc_bar = "---------------------------------------------------------"
@toc = CSV.read("toc_book.csv", "r")
end
def print_toc
print_toc_header
print_toc_body
end
def print_toc_header
puts @toc_header.center(58) + "\n" + @toc_bar
end
def print_toc_body
@toc.each_with_index do |element,index,length = 38|
print "Chapter #{index+1}: #{element[0]}"
(length - element[0].length).times {|i| print "."}
print "p. #{element[1]}" + "\n"
end
end
end
toc = TableOfContents.new
toc.print_toc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment