Class: Gasciiart::Builder
- Inherits:
-
Object
- Object
- Gasciiart::Builder
- Defined in:
- lib/gasciiart/builder.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #add_runner ⇒ Object
-
#build! ⇒ Object
Where all the magic happens Setups up the output and loops through each file from the source (in ‘ls` order) Creating a commit for each file.
- #create_commit(infile_name) ⇒ Object
-
#initialize(source, target, options = {}) ⇒ Builder
constructor
A new instance of Builder.
- #rewrite_animation_frame(infile_name) ⇒ Object
-
#setup_target ⇒ Object
Creates and git inits the target directory.
Constructor Details
#initialize(source, target, options = {}) ⇒ Builder
Returns a new instance of Builder.
6 7 8 9 10 11 12 13 14 |
# File 'lib/gasciiart/builder.rb', line 6 def initialize(source, target, = {}) @source, @target, @options = source, target, @source = "#{@source}/" unless @source[-1..-1] == '/' @target = "#{@target}/" unless @target[-1..-1] == '/' @verbose = [:verbose] @starting_dir = Dir.pwd @target_animation = "#{@target}animation.txt" end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/gasciiart/builder.rb', line 4 def @options end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/gasciiart/builder.rb', line 4 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
4 5 6 |
# File 'lib/gasciiart/builder.rb', line 4 def target @target end |
Instance Method Details
#add_runner ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gasciiart/builder.rb', line 62 def add_runner filename = "#{@target}run.sh" File.open(filename, 'w') do |f| f.write Gasciiart::RUNNER end File.chmod 0755, filename run %{git add run.sh && git commit -m "Added run.sh"} end |
#build! ⇒ Object
Where all the magic happens Setups up the output and loops through each file from the source (in ‘ls` order) Creating a commit for each file
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gasciiart/builder.rb', line 19 def build! test_git! file_list = Dir.glob("#{@source}*").sort # Pull the file list before creating the target directory setup_target add_runner file_list.each do |infile_name| rewrite_animation_frame infile_name create_commit infile_name end end |
#create_commit(infile_name) ⇒ Object
58 59 60 |
# File 'lib/gasciiart/builder.rb', line 58 def create_commit(infile_name) run %{git add animation.txt && git commit -m "#{infile_name}"} end |
#rewrite_animation_frame(infile_name) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/gasciiart/builder.rb', line 49 def rewrite_animation_frame(infile_name) log "Writing #{infile_name}" File.open(infile_name) do |infile| File.open(@target_animation, 'w') do |outfile| outfile.write infile.read # This could be streamed, but a single animation frame is small enough. Let's start simple end end end |
#setup_target ⇒ Object
Creates and git inits the target directory
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gasciiart/builder.rb', line 35 def setup_target log "Setting up #{@target}" if File.exists? @target raise ArgumentError, %{Target directory "#{@target}" already exists} end FileUtils.mkdir @target run "git init ." # TODO: Create runner file end |