ltsv 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -63,10 +63,11 @@ Dumped objects should respond to :to_hash.
63
63
  ### Author and Contributors
64
64
 
65
65
  * Author
66
- * Naoto "Kevin" IMAI TOYODA <condor1226@github.com>
66
+ * Naoto "Kevin" IMAI TOYODA <condor1226@github.com>
67
67
 
68
68
  * Contributors
69
- * Naoto SHINGAKI <https://github.com/naoto/>
69
+ * Naoto SHINGAKI <https://github.com/naoto/>
70
+ * chezou <https://github.com/chezou>
70
71
 
71
72
  ## Contributing
72
73
 
@@ -4,7 +4,7 @@
4
4
  #
5
5
  #
6
6
  module LTSV
7
- VERSION = "0.0.2"
7
+ VERSION = "0.0.3"
8
8
 
9
9
  # Parsing given stream or string.
10
10
  # If you specified a stream as the first argument,
@@ -55,9 +55,9 @@ module LTSV
55
55
 
56
56
  case io_or_string
57
57
  when String
58
- File.open(io_or_string, "r:#{encoding}"){|f|parse_io(f)}
58
+ File.open(io_or_string, "r:#{encoding}"){|f|parse_io(f, options)}
59
59
  when IO
60
- parse_io(io)
60
+ parse_io(io_or_string, options)
61
61
  end
62
62
  end
63
63
 
@@ -95,9 +95,14 @@ module LTSV
95
95
 
96
96
  string.split("\t").inject({}) do |h, i|
97
97
  (key, value) = i.split(':', 2)
98
+ next unless key
98
99
  key = key.to_sym if symbolize_keys
99
100
  unescape!(value)
100
- h[key] = value.empty? ? nil : value
101
+ h[key] = case value
102
+ when nil then nil
103
+ when '' then nil
104
+ else value
105
+ end
101
106
  h
102
107
  end
103
108
  end
@@ -42,12 +42,22 @@ describe LTSV do
42
42
  [{:label1 => 'value1', :label2 => 'value\\nvalue'},
43
43
  {:label3 => 'value3', :label4 => 'value\\rvalue'},
44
44
  {:label5 => 'value5', :label6 => 'value\\tvalue'},
45
- {:label7 => 'value7', :label8 => 'value\\\\value'}]
45
+ {:label7 => 'value7', :label8 => 'value\\\\value'},
46
+ {:label9 => 'value9', :label10 => nil, :label11 => 'value11'}]
46
47
  end
47
48
  end
48
49
  end
49
50
 
50
51
  describe :load do
52
+ specify 'can load labeled tab separated values from file' do
53
+ stream = File.open("#{File.dirname(__FILE__)}/test.ltsv")
54
+ LTSV.load(stream).should ==
55
+ [{:label1 => 'value1', :label2 => 'value\\nvalue'},
56
+ {:label3 => 'value3', :label4 => 'value\\rvalue'},
57
+ {:label5 => 'value5', :label6 => 'value\\tvalue'},
58
+ {:label7 => 'value7', :label8 => 'value\\\\value'},
59
+ {:label9 => 'value9', :label10 => nil, :label11 => 'value11'}]
60
+ end
51
61
  end
52
62
 
53
63
  describe :dump do
@@ -2,3 +2,4 @@ label1:value1 label2:value\\nvalue
2
2
  label3:value3 label4:value\\rvalue
3
3
  label5:value5 label6:value\\tvalue
4
4
  label7:value7 label8:value\\\\value
5
+ label9:value9 label10: label11:value11
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ltsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec