Class: Saga::Runner
- Inherits:
-
Object
- Object
- Saga::Runner
- Defined in:
- lib/saga/runner.rb
Class Method Summary collapse
Instance Method Summary collapse
- #autofill(filename) ⇒ Object
- #convert(filename, options) ⇒ Object
- #copy_template(destination) ⇒ Object
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
- #new_file ⇒ Object
- #parser ⇒ Object
- #planning(filename) ⇒ Object
- #run ⇒ Object
- #run_command(command, options) ⇒ Object
- #write_parsed_document(filename) ⇒ Object
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 |
# File 'lib/saga/runner.rb', line 5 def initialize(argv) @argv = argv @options = {} end |
Class Method Details
.author ⇒ Object
113 114 115 116 |
# File 'lib/saga/runner.rb', line 113 def self. name = `osascript -e "long user name of (system info)" &1> /dev/null`.strip {:name => name} end |
Instance Method Details
#autofill(filename) ⇒ Object
64 65 66 67 68 |
# File 'lib/saga/runner.rb', line 64 def autofill(filename) document = Saga::Parser.parse(File.read(filename)) document.autofill_ids Saga::Formatter.saga_format(document) end |
#convert(filename, options) ⇒ Object
50 51 52 |
# File 'lib/saga/runner.rb', line 50 def convert(filename, ) Saga::Formatter.format(Saga::Parser.parse(File.read(filename)), ) end |
#copy_template(destination) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/saga/runner.rb', line 74 def copy_template(destination) if File.exist?(destination) puts "The directory `#{destination}' already exists!" else require 'fileutils' FileUtils.mkdir_p(destination) FileUtils.cp(File.join(Saga::Formatter.template_path, 'default/helpers.rb'), destination) FileUtils.cp(File.join(Saga::Formatter.template_path, 'default/document.erb'), destination) end end |
#new_file ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/saga/runner.rb', line 33 def new_file document = Saga::Document.new document.title = 'Title' document. << self.class. document.stories[''] = [{ :description => 'As a writer I would like to write stories so developers can implement them.', :id => 1, :status => 'todo' }] document.definitions[''] = [{ :title => 'Writer', :definition => 'Someone who is responsible for writing down requirements in the form of stories' }] Saga::Formatter.saga_format(document) end |
#parser ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/saga/runner.rb', line 10 def parser @parser ||= OptionParser.new do |opts| opts. = "Usage: saga [command]" opts.separator "" opts.separator "Commands:" opts.separator " new - prints a blank stub" opts.separator " convert <filename> - convert the stories to HTML" opts.separator " inspect <filename> - print the internals of the document" opts.separator " autofill <filename> - adds an id to stories without one" opts.separator " planning <filename> - shows the planning of stories in iterations" opts.separator " template <dir> - creates a template directory" opts.separator "" opts.separator "Options:" opts.on("-t", "--template DIR", "Use an external template for conversion to HTML") do |template_path| @options[:template] = File.(template_path) end opts.on("-h", "--help", "Show help") do puts opts exit end end end |
#planning(filename) ⇒ Object
70 71 72 |
# File 'lib/saga/runner.rb', line 70 def planning(filename) Saga::Planning.new(Saga::Parser.parse(File.read(filename))).to_s end |
#run ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/saga/runner.rb', line 104 def run parser.parse!(@argv) if command = @argv.shift run_command(command, @options) else puts parser.to_s end end |
#run_command(command, options) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/saga/runner.rb', line 85 def run_command(command, ) case command when 'new' puts new_file when 'convert' puts convert(File.(@argv[0]), ) when 'inspect' write_parsed_document(File.(@argv[0])) when 'autofill' puts autofill(File.(@argv[0])) when 'planning' puts planning(File.(@argv[0])) when 'template' copy_template(File.(@argv[0])) else puts convert(File.(command), ) end end |
#write_parsed_document(filename) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/saga/runner.rb', line 54 def write_parsed_document(filename) document = Saga::Parser.parse(File.read(filename)) puts document.title document..each { || p } puts document.stories.each { |header, stories| puts header; stories.each { |story| p story } } puts document.definitions.each { |header, definitions| puts header; definitions.each { |definition| p definition } } end |