lib/markov_uuid/storage.rb in markov_uuid-0.0.3 vs lib/markov_uuid/storage.rb in markov_uuid-0.0.5

- old
+ new

@@ -1,38 +1,19 @@ require "yaml" require "fileutils" module MarkovUuid class Storage - include KeySelector - attr_accessor :data - - def initialize(data = nil ) - @data = data if data.class == Hash - @data ||= Hash.new + def initialize filename + @filename = filename end - def add words - words.add_to @data - end + attr_accessor :data, :filename - def to_words length = 100 - key = Markov::SEPARATOR - word = "" - - result = length.times.map do - word = @data[key].sample rescue nil - key = new_key key, word - word - end.compact - - Markov.new result - end - - def save filename + def save File.open(filename, "w"){|f| YAML.dump(@data, f) } end - def load filename + def load FileUtils.touch filename File.open(filename) do |f| @data = YAML.load f end end