Commits

soycamo  committed e23ca9b

wip realizing that structs are immutable. d'oh

  • Participants
  • Parent commits 0731181

Comments (0)

Files changed (2)

-require 'pp'
-
 class Kamishibai
   require 'iconv' unless String.method_defined?(:encode)
   attr_accessor :slideset
 
   # The Slip N Slide holds our wonky data.
-  SlipnSlide = Struct.new(:title, :raw_attributes) 
+  SlipnSlide = Struct.new(:title, :raw_attributes, :attributes) 
 
   def initialize(gamefile_path)
     #gamefile_path = File.expand_path "~/Projects/tapestry/test\ samples/KamishibaiMasterClass/gamefile.txt" #use ARGV here
       #puts line
       if line =~ %r{^\[(.+)\]}
         @slideset << current_slide unless current_slide.nil? 
-        current_slide = SlipnSlide.new(line[1..(line.length - 2)], [])
+        # use line.tr
+        current_slide = SlipnSlide.new(line[1..(line.length - 2)], '', [])
       else
-        current_slide.raw_attributes << line if current_slide
+        if line =~ %r{^\w}
+          line = line.rjust(line.length + 1)
+        end
+        current_slide.raw_attributes += line if current_slide
       end
 
     end
     @slideset << current_slide
-
+    
+    # dang I wanna use @slideset.collect!(&:parse_attributes) 'cause I <3 that syntax
+    @slideset.collect! { |slide| Kamishibai.parse_attributes!(slide) }
   end
 
-#  def parse_attributes(attr_array)
-#    attr_array.inject([]) do |memo, str| 
-#      memo << str
-#      end
-#    end
+  def self.parse_attributes!(slide)
+    attrs = slide.raw_attributes
+    attrs = attrs.gsub('@', '||@').split('||')
+    attrs.delete_if{|attr| attr.empty? }
+    slide.attributes = attrs
+  end
 end
 
 #example = slideset.select { |slide| slide.title == "A4" }.first                            

File tapestry_spec.rb

 require 'rspec'
 require './tapestry'
+require 'pp'
 
 describe Kamishibai do
+
+  before do
+    @ksb = Kamishibai.new("./example_gamefile.txt")
+  end
+
+  it "in a typical situation, should create correct number of slides" do
+    @ksb.slideset.length.should == 4
+  end
+
   it "should merge attributes that included newlines" do
-    ksb = Kamishibai.new("./example_gamefile.txt")
-    ksb.slideset.length.should == 4
+    pending
+    slide = @ksb.slideset.first
+    clean_attributes = 
+      ["@image = Conclusion.bmp",
+       "@music = shota(Rally the troops).mid",
+       "@description = Conclusion. Here you just basically touch things up and prepare the story for its final form to be published (read by others), so this is what you need to remember...",
+       "@option3 = --->",
+       "@link3 = A19",
+       "@option4 = <---",
+       "@link4 = A17"]
+
+    Kamishibai.parse_attributes!(slide).should == clean_attributes
+  end
+
+  it "should return the correct number of attributes" do
+    slide = @ksb.slideset.first
+    slide.attributes.length.should == 7
   end
 end