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 +3 -2
- data/lib/ltsv.rb +9 -4
- data/spec/ltsv_spec.rb +11 -1
- data/spec/test.ltsv +1 -0
- metadata +2 -2
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
|
-
|
66
|
+
* Naoto "Kevin" IMAI TOYODA <condor1226@github.com>
|
67
67
|
|
68
68
|
* Contributors
|
69
|
-
|
69
|
+
* Naoto SHINGAKI <https://github.com/naoto/>
|
70
|
+
* chezou <https://github.com/chezou>
|
70
71
|
|
71
72
|
## Contributing
|
72
73
|
|
data/lib/ltsv.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#
|
5
5
|
#
|
6
6
|
module LTSV
|
7
|
-
VERSION = "0.0.
|
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(
|
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] =
|
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
|
data/spec/ltsv_spec.rb
CHANGED
@@ -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
|
data/spec/test.ltsv
CHANGED
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.
|
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-
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|