Created
December 3, 2008 16:58
-
-
Save vapidbabble/31612 to your computer and use it in GitHub Desktop.
takes palm docs of the dhammapada and the vacana and generates a daily reading
This file contains 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
#takes palm docs of the buddhists texts dhammapada and the vacana and | |
#generates a daily reading | |
#get the Palm docsbooks buddhavacana.pdb and dhammapada.pdb here | |
#http://www.buddhavacana.net/index.php?d=/download/&f=books | |
# need the palm gem and chronic | |
require 'rubygems' | |
require 'palm' | |
require 'chronic' | |
class ReadForToday | |
#attr_reader :vacana, :dhamma | |
def initialize(date, linelen) | |
@datestr=date | |
#just look in the current run dir, yes I'm lame. | |
@vacana=dumprecord(Palm::PDB.new('buddhavacana.pdb')) | |
@dhamma=dumprecord(Palm::PDB.new('dhammapada.pdb')) | |
@linelen=linelen | |
end | |
private | |
#wrap text stolen form here | |
#http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/ | |
def wrap_text(txt, col = @linelen) | |
txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,"\\1\\3\n") | |
end | |
def dumprecord(pdb) | |
#get the record for day of year | |
record=pdb.data[Chronic.parse(@datestr).yday-1] | |
record.data.gsub!(/\c@/,"") | |
end | |
def sep | |
sep="" | |
@linelen.times {|i| sep+="*"} | |
sep+="\n" | |
end | |
def format(raw,header) | |
header+="\n" | |
record=wrap_text(sep+header+raw.chomp)+"\n" | |
end | |
public | |
def vacana_print | |
format(@vacana,"Buddha Vacana") | |
end | |
def dhamma_print | |
format(@dhamma, "Dhammapada") | |
end | |
end | |
if __FILE__ == $0 | |
myread= ReadForToday.new("today",72) | |
puts myread.vacana_print | |
puts myread.dhamma_print | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment