Commits

soycamo committed 60356e8

Added two methods:
- SlipnSlide.to_twee which converts a slide to a string that Twee expects
- Kamishibai.to_hash to create a sensible hash in which to generate Twee data

  • Participants
  • Parent commits 9ae2298

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, :attributes) 
+  SlipnSlide = Struct.new(:title, :raw_attributes, :attributes) do
+    def to_twee
+      twee = ":: #{title}\n"
+      twee << attributes['description'] + "\n"
+      twee
+    end
+  end
 
   def initialize(gamefile_path)
     #gamefile_path = File.expand_path "~/Projects/tapestry/test\ samples/KamishibaiMasterClass/gamefile.txt" #use ARGV here
     attrs = slide.raw_attributes
     attrs = attrs.gsub('@', '||@').split('||')
     attrs.delete_if{|attr| attr.empty? }
-    slide.attributes = attrs
+    slide.attributes = Kamishibai.to_hash attrs
     slide
   end
+
+  def self.to_hash ary
+    hash = {}
+    ary.collect do |str| 
+      key, value = str.split(' = ')
+      hash[key.tr('@', '')] = value
+    end
+    hash
+  end
 end
 
 #example = slideset.select { |slide| slide.title == "A4" }.first                            
     @ksb.slideset.length.should == 4
   end
 
-  it "should merge attributes that included newlines" do
+  it "should clean attributes" do
     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"]
+      {"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)
     slide.attributes.should == clean_attributes
     slide = @ksb.slideset.first
     slide.attributes.length.should == 7
   end
+
+  it "should format a slide in Twee format" do
+    twee_output = <<-TW
+:: A18
+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...
+TW
+    slide = @ksb.slideset.first
+    slide.to_twee.should == twee_output 
+  end
 end