Created
October 11, 2012 03:11
-
-
Save arn-e/3869939 to your computer and use it in GitHub Desktop.
toc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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