ltsv 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +6 -19
- data/ReleaseNote.md +19 -0
- data/lib/ltsv.rb +16 -17
- data/spec/ltsv_spec.rb +10 -0
- metadata +10 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2f79ee48bcd1bcdc0fbf7bce5eec5852253d1bbba917fd3412752b503801c8a8
|
4
|
+
data.tar.gz: cb1005833439ec57f4c7d9bd20815205b81c6bea50d5dce847af0b2c3f48893b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22f69a0c8c1eabac0e76a367649357ca815ba4e16dd4734fca6e52b5c372c97314159ab92787f0771aff871d93d1a01c5d8d627895119f1dc107f499d958918c
|
7
|
+
data.tar.gz: 497d706a01ef79baece93cb68ca199fa276ed5bfc01adf4c0c31951e187002d095cddfe3654ce9f9e21fa9bcfdb18691d35e533cb46be09eb6231f1f13b5a0a0
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ In addition, if you manage gems with bundler, you should add the statement below
|
|
31
31
|
|
32
32
|
# parse string
|
33
33
|
string = "label1:value1\tlabel2:value2"
|
34
|
-
values = LTSV.parse(string) # => {:label1 => "value1", :label2 => "value2"}
|
34
|
+
values = LTSV.parse(string) # => [{:label1 => "value1", :label2 => "value2"}]
|
35
35
|
|
36
36
|
# parse via stream
|
37
37
|
# content: as below
|
@@ -42,14 +42,12 @@ In addition, if you manage gems with bundler, you should add the statement below
|
|
42
42
|
# => [{:label1_1 => "value1_2", :label1_2 => "value1_2"},
|
43
43
|
# {:label2_1 => "value2_2", :label2_2 => "value2_2"}]
|
44
44
|
|
45
|
-
Current limitation: parsed string should be in one line. If you include any special chars that may affect to the processing( "\r", "\n", "\t", "\\"), you should properly escape it with backslash.
|
46
|
-
|
47
45
|
### loading LTSV file
|
48
46
|
|
49
|
-
#
|
50
|
-
values = LTSV.
|
47
|
+
# load via path
|
48
|
+
values = LTSV.load("some_path.ltsv")
|
51
49
|
|
52
|
-
#
|
50
|
+
# load via stream
|
53
51
|
stream = File.open("some_file.ltsv", "r")
|
54
52
|
values = LTSV.load(stream) # => same as LTSV.parse(stream)
|
55
53
|
|
@@ -63,7 +61,7 @@ Dumped objects should respond to :to_hash.
|
|
63
61
|
### Author and Contributors
|
64
62
|
|
65
63
|
* Author
|
66
|
-
* Naoto "Kevin" IMAI TOYODA <
|
64
|
+
* Naoto "Kevin" IMAI TOYODA <https://github.com/condor/>
|
67
65
|
|
68
66
|
* Contributors
|
69
67
|
* Naoto SHINGAKI <https://github.com/naoto/>
|
@@ -72,18 +70,7 @@ Dumped objects should respond to :to_hash.
|
|
72
70
|
|
73
71
|
### History
|
74
72
|
|
75
|
-
|
76
|
-
Thanks to Masato Ikeda.
|
77
|
-
parse(String) method now accepts multi-line string and returns an Array of Hash. for single line String, use the new parse_line method.
|
78
|
-
* 2013/02/11 0.0.3
|
79
|
-
Thanks to Chezou.
|
80
|
-
* Added the specs for load() method.
|
81
|
-
* Fixed the bug when handling empty keys or values.
|
82
|
-
* 2013/02/08 0.0.2
|
83
|
-
Bug Fix for parse_io() internal method, which affects the behaviour when parse() method receives an IO instance for the first argument.
|
84
|
-
Thanks to Naoto Shingaki.
|
85
|
-
* 2013/02/07 0.0.1
|
86
|
-
First Release.
|
73
|
+
See ReleaseNote.md.
|
87
74
|
|
88
75
|
## Contributing
|
89
76
|
|
data/ReleaseNote.md
CHANGED
@@ -1,6 +1,25 @@
|
|
1
1
|
#History
|
2
2
|
----
|
3
3
|
|
4
|
+
0.1.2 (2018/11/22)
|
5
|
+
------------------
|
6
|
+
* parse_line(String) is now public. (Thanks to Satoshi "Moris" Tagomori <https://github.com/tagomoris>)
|
7
|
+
* README improved. (thanks to sasaki takeru <https://github.com/takeru>)
|
8
|
+
* Unexpected ArgumentError of LTSV.dump with the argument that contains the instance of the specific type. (thanks to Ryo Nakamura <https://github.com/r7kamura>)
|
9
|
+
|
10
|
+
0.1.0 (2013/02/12)
|
11
|
+
------------------
|
12
|
+
* parse(String) method now accepts multi-line string and returns an Array of Hash. for single line String, use the new parse_line method.
|
13
|
+
|
14
|
+
(Thanks to Masato Ikeda)
|
15
|
+
|
16
|
+
0.0.3 (2013/02/11)
|
17
|
+
------------------
|
18
|
+
* Added the specs for load() method.
|
19
|
+
* Fixed the bug when handling empty keys or values.
|
20
|
+
|
21
|
+
(Thanks to Aki Ariga <https://github.com/chezou>)
|
22
|
+
|
4
23
|
0.0.2 (2013/02/08)
|
5
24
|
------------------
|
6
25
|
Fixed a bug with :parse method for handling an IO argument. (Thanks to Naoto SINGAKI <https://github.com/naoto/>)
|
data/lib/ltsv.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#
|
5
5
|
#
|
6
6
|
module LTSV
|
7
|
-
VERSION = "0.1.
|
7
|
+
VERSION = "0.1.2"
|
8
8
|
|
9
9
|
# Parsing given stream or string.
|
10
10
|
# If you specified a stream as the first argument,
|
@@ -83,17 +83,7 @@ module LTSV
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
def parse_io(io, options)#:nodoc:
|
89
|
-
io.map{|l|parse_line l.chomp, options}
|
90
|
-
end
|
91
|
-
|
92
|
-
def parse_string(string, options)#:nodoc:
|
93
|
-
string.chomp.split($/).map{|l|parse_line l, options}
|
94
|
-
end
|
95
|
-
|
96
|
-
def parse_line(line, options)#:nodoc:
|
86
|
+
def parse_line(line, options={})#:nodoc:
|
97
87
|
symbolize_keys = options.delete(:symbolize_keys)
|
98
88
|
symbolize_keys = true if symbolize_keys.nil?
|
99
89
|
|
@@ -111,6 +101,16 @@ module LTSV
|
|
111
101
|
end
|
112
102
|
end
|
113
103
|
|
104
|
+
private
|
105
|
+
|
106
|
+
def parse_io(io, options)#:nodoc:
|
107
|
+
io.map{|l|parse_line l.chomp, options}
|
108
|
+
end
|
109
|
+
|
110
|
+
def parse_string(string, options)#:nodoc:
|
111
|
+
string.chomp.split($/).map{|l|parse_line l, options}
|
112
|
+
end
|
113
|
+
|
114
114
|
def unescape!(string)#:nodoc:
|
115
115
|
return nil if !string || string == ''
|
116
116
|
|
@@ -133,12 +133,11 @@ module LTSV
|
|
133
133
|
def escape(string)#:nodoc:
|
134
134
|
value = string.kind_of?(String) ? string.dup : string.to_s
|
135
135
|
|
136
|
-
value.gsub!("\\", "\\\\")
|
137
|
-
value.gsub!("\n", "\\n")
|
138
|
-
value.gsub!("\r", "\\r")
|
139
|
-
value.gsub!("\t", "\\t")
|
140
|
-
|
141
136
|
value
|
137
|
+
.gsub("\\", "\\\\")
|
138
|
+
.gsub("\n", "\\n")
|
139
|
+
.gsub("\r", "\\r")
|
140
|
+
.gsub("\t", "\\t")
|
142
141
|
end
|
143
142
|
|
144
143
|
module_function :load, :parse, :dump, :parse_io, :parse_string, :parse_line, :unescape!, :escape
|
data/spec/ltsv_spec.rb
CHANGED
@@ -97,5 +97,15 @@ describe LTSV do
|
|
97
97
|
specify 'fails when object to dump does not respond to :to_hash' do
|
98
98
|
lambda{LTSV.dump(Object.new)}.should raise_exception(ArgumentError)
|
99
99
|
end
|
100
|
+
|
101
|
+
context 'when given Hash includes a value that returns a frozen String' do
|
102
|
+
let(:hash) do
|
103
|
+
{ label: double(to_s: "value".freeze) }
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'does not fail' do
|
107
|
+
LTSV.dump(hash).should == 'label:value'
|
108
|
+
end
|
109
|
+
end
|
100
110
|
end
|
101
111
|
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ltsv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- condor
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-11-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: A Parser / Dumper for LTSV
|
@@ -34,7 +31,7 @@ executables: []
|
|
34
31
|
extensions: []
|
35
32
|
extra_rdoc_files: []
|
36
33
|
files:
|
37
|
-
- .gitignore
|
34
|
+
- ".gitignore"
|
38
35
|
- Gemfile
|
39
36
|
- LICENSE.txt
|
40
37
|
- README.md
|
@@ -47,27 +44,26 @@ files:
|
|
47
44
|
- spec/test.ltsv
|
48
45
|
homepage: https://github.com/condor/ltsv
|
49
46
|
licenses: []
|
47
|
+
metadata: {}
|
50
48
|
post_install_message:
|
51
49
|
rdoc_options: []
|
52
50
|
require_paths:
|
53
51
|
- lib
|
54
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
53
|
requirements:
|
57
|
-
- -
|
54
|
+
- - ">="
|
58
55
|
- !ruby/object:Gem::Version
|
59
56
|
version: '0'
|
60
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
58
|
requirements:
|
63
|
-
- -
|
59
|
+
- - ">="
|
64
60
|
- !ruby/object:Gem::Version
|
65
61
|
version: '0'
|
66
62
|
requirements: []
|
67
63
|
rubyforge_project:
|
68
|
-
rubygems_version:
|
64
|
+
rubygems_version: 2.7.8
|
69
65
|
signing_key:
|
70
|
-
specification_version:
|
66
|
+
specification_version: 4
|
71
67
|
summary: A Parser / Dumper for LTSV
|
72
68
|
test_files:
|
73
69
|
- spec/ltsv_spec.rb
|