From 4052d534b2b69ab611ac53fba2451dc01766d73f Mon Sep 17 00:00:00 2001 From: Jaiden Mispy <^_^@mispy.me> Date: Sat, 25 Oct 2014 04:26:52 -0700 Subject: [PATCH] Save only necessary data into model --- lib/twitter_ebooks/model.rb | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/twitter_ebooks/model.rb b/lib/twitter_ebooks/model.rb index 33af43d..e7b6958 100644 --- a/lib/twitter_ebooks/model.rb +++ b/lib/twitter_ebooks/model.rb @@ -15,7 +15,23 @@ module Ebooks end def self.load(path) - Marshal.load(File.open(path, 'rb') { |f| f.read }) + props = Marshal.load(File.open(path, 'rb') { |f| f.read }) + @tokens = props[:tokens] + @sentences = props[:sentences] + @mentions = props[:mentions] + @keywords = props[:keywords] + end + + def save(path) + File.open(path, 'wb') do |f| + f.write(Marshal.dump({ + tokens: @tokens, + sentences: @sentences, + mentions: @mentions, + keywords: @keywords + })) + end + self end def initialize @@ -98,13 +114,6 @@ module Ebooks self end - def save(path) - File.open(path, 'wb') do |f| - f.write(Marshal.dump(self)) - end - self - end - def fix(tweet) # This seems to require an external api call #begin