#!/usr/bin/env ruby # == Usage # wagon [options] [output_file] # # == Options # -h, --help Displays this help message # -v, --version Display the version, then exit # -V, --verbose Verbose output # -t, --title The title displayed on each page (default is the ward name) # -r, --rows Number of rows per page (default is 6) # -c, --columns Number of columns per page (default is 7) # -p, --padding Padding between households (default is 2) # -f, --font-size Primary font size (default is 8) # --page-numbers Include page numbers in the footer, e.g. (1 of 3) # --no-date Do not include the current date in the footer # --no-picture Do not include pictures # --no-address Do not include street addresses # --no-phone Do not include phone numbers # --no-email Do not include email addresses # # == Copyright # Copyright (c) 2009 Devin Christensen. See LICENSE for details. $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'optparse' require 'rdoc/usage' require 'ostruct' require 'wagon' require 'highline/import' class WagonApp def initialize(arguments, stdin) @arguments = arguments @stdin = stdin @options = OpenStruct.new() # Set defaults @options.verbose = false @options.title = nil @options.rows = 6 @options.columns = 7 @options.padding = 2 @options.font_size = 8 @options.page_numbers = false @options.include_date = true @options.picture = true @options.address = true @options.phone_number = true @options.email = true @options.output_file = "./photo_directory.pdf" end def run if arguments_valid? puts "Start at #{DateTime.now}\n\n" if @options.verbose output_options if @options.verbose # [Optional] process puts "\nFinished in #{DateTime.now}" if @options.verbose else output_usage end end protected def arguments_valid? # Specify options opts = OptionParser.new opts.on('-v', '--version') { output_version ; exit 0 } opts.on('-h', '--help') { output_help } opts.on('-V', '--verbose') { @options.verbose = true } opts.on('-t', '--title=TITLE') { |title| @options.title = title } opts.on('-r', '--rows=ROWS') { |rows| @options.rows = rows } opts.on('-c', '--columns=COLUMNS') { |columns| @options.columns = columns } opts.on('-p', '--padding=PADDING') { |padding| @options.padding = padding } opts.on('-f', '--font-size=SIZE') { |size| @options.font_size = size } opts.on('--page-numbers') { @options.page_numbering = true } opts.on('--no--date') { @options.include_date = false } opts.on('--no-picture') { @options.picture = false } opts.on('--no-address') { @options.address = false } opts.on('--no-phone') { @options.phone_number = false } opts.on('--no-email') { @options.email = false } opts.parse!(@arguments) rescue return false @options.output_file = @arguments.last unless @arguments.empty? true end def output_options puts "Options:\n" @options.marshal_dump.each do |name, val| puts " #{name} = #{val}" end end def output_help output_version RDoc::usage() end def output_usage RDoc::usage('usage') # gets usage from comments above end def output_version puts "#{File.basename(__FILE__)} version #{Wagon::VERSION}" end def process username = ask("What is your lds.org username? ") password = ask("What is your lds.org password? ") { |q| q.echo = "*" } user = Wagon::connect(username, password) puts "\nAlright, we're in!" puts "I'm gonna go ahead and create that PDF for ya now." puts "It might take a few minutes to gather all the info" puts "so grab a crisp cool beverage, sit back and relax." puts "I'll take it from here." directory = user.ward.to_pdf( @options.marshal_dump ) directory.render_file(@options.output_file) puts "\nFinished. Enjoy.\n" rescue Wagon::AuthenticationFailure puts "\nThe username and password combination you entered is invalid." rescue if @options.verbose raise else puts "\nI encountered an unexpected problem, and I don't know what to do. :(" end end end app = WagonApp.new(ARGV, STDIN) app.run