diff options
author | Patrick Simianer <p@simianer.de> | 2015-03-04 15:24:54 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2015-03-04 15:24:54 +0100 |
commit | 2ab23ec844862b3ec034f805f74420f36ac639f5 (patch) | |
tree | c048c162b2e76c6338599642ceb9f971358f8507 /lib | |
parent | 2af1e4d316095c550b6de29e624cb2925a6e78da (diff) |
SparseVector: fix from_kv -> bump to v1.2.3
Diffstat (limited to 'lib')
-rw-r--r-- | lib/zipf/SparseVector.rb | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/zipf/SparseVector.rb b/lib/zipf/SparseVector.rb index e9af799..837403a 100644 --- a/lib/zipf/SparseVector.rb +++ b/lib/zipf/SparseVector.rb @@ -37,7 +37,7 @@ class SparseVector < Hash end def from_s s - from_h eval(s) + from_h eval(s.strip) end def self.from_s s @@ -55,12 +55,18 @@ class SparseVector < Hash end def from_kv s, sep='=', join=/\s/ - s.split(join).each { |i| + s.strip.split(join).each { |i| k,v = i.split(sep) self[k] = v.to_f } end + def self.from_kv s, sep='=', join=/\s/ + v = SparseVector.new + v.from_kv s, sep, join + return v + end + def to_json JSON.dump self.to_h end @@ -75,12 +81,6 @@ class SparseVector < Hash return v end - def self.from_kv s, sep='=', join=/\s/ - v = SparseVector.new - v.from_kv s, sep, join - return v - end - def from_file fn, sep='=' f = ReadFile.new(fn) while line = f.gets |