abroad 4.1.3 → 4.2.0
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 +4 -4
- data/lib/abroad.rb +2 -0
- data/lib/abroad/extractors.rb +1 -0
- data/lib/abroad/extractors/txt.rb +8 -0
- data/lib/abroad/extractors/txt/lines_extractor.rb +22 -0
- data/lib/abroad/extractors/txt/txt_extractor.rb +17 -0
- data/lib/abroad/serializers.rb +1 -0
- data/lib/abroad/serializers/txt.rb +8 -0
- data/lib/abroad/serializers/txt/lines_serializer.rb +52 -0
- data/lib/abroad/serializers/txt/txt_serializer.rb +15 -0
- data/lib/abroad/version.rb +1 -1
- data/spec/extractors/txt/lines_extractor_spec.rb +23 -0
- data/spec/serializers/txt/lines_serializer_spec.rb +31 -0
- data/spec/spec_helper.rb +12 -3
- metadata +11 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0fe36cd26c80451ce1514284dd1d4948797e8a95
|
|
4
|
+
data.tar.gz: c1645f6188fc0494a51153bfb2a06ca4220b697f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9995680ee6439cad5c4d6086fa3efde9fcd9b12ffc2c8cf410d97aa5a6dca9539b0bcd49e1c66dd444045bed8c413098f90fa43dc205968e8588b5bd07ac7c5d
|
|
7
|
+
data.tar.gz: e6609ea0b1c92ba0130db811f359e7aa48daf9659e787340bb671d952b0720fe1e25361c2690e2a425d7b32f41bc96d636cd50b2521037f0bdc8a75863dd09bf
|
data/lib/abroad.rb
CHANGED
|
@@ -8,10 +8,12 @@ module Abroad
|
|
|
8
8
|
Extractors.register('yaml/dotted-key', Extractors::Yaml::DottedKeyExtractor)
|
|
9
9
|
Extractors.register('json/key-value', Extractors::Json::KeyValueExtractor)
|
|
10
10
|
Extractors.register('xml/android', Extractors::Xml::AndroidExtractor)
|
|
11
|
+
Extractors.register('txt/lines', Extractors::Txt::LinesExtractor)
|
|
11
12
|
|
|
12
13
|
Serializers.register('yaml/rails', Serializers::Yaml::RailsSerializer)
|
|
13
14
|
Serializers.register('json/key-value', Serializers::Json::KeyValueSerializer)
|
|
14
15
|
Serializers.register('xml/android', Serializers::Xml::AndroidSerializer)
|
|
16
|
+
Serializers.register('txt/lines', Serializers::Txt::LinesSerializer)
|
|
15
17
|
|
|
16
18
|
class << self
|
|
17
19
|
def extractors
|
data/lib/abroad/extractors.rb
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'json/stream'
|
|
2
|
+
|
|
3
|
+
module Abroad
|
|
4
|
+
module Extractors
|
|
5
|
+
module Txt
|
|
6
|
+
|
|
7
|
+
class LinesExtractor < TxtExtractor
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def each_entry
|
|
11
|
+
return to_enum(__method__) unless block_given?
|
|
12
|
+
|
|
13
|
+
stream.each_line.with_index do |line, idx|
|
|
14
|
+
# keys should always be strings
|
|
15
|
+
yield idx.to_s, line.chomp
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/abroad/serializers.rb
CHANGED
|
@@ -2,6 +2,7 @@ module Abroad
|
|
|
2
2
|
module Serializers
|
|
3
3
|
autoload :Json, 'abroad/serializers/json'
|
|
4
4
|
autoload :Serializer, 'abroad/serializers/serializer'
|
|
5
|
+
autoload :Txt, 'abroad/serializers/txt'
|
|
5
6
|
autoload :Trie, 'abroad/serializers/trie'
|
|
6
7
|
autoload :Xml, 'abroad/serializers/xml'
|
|
7
8
|
autoload :Yaml, 'abroad/serializers/yaml'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Abroad
|
|
2
|
+
module Serializers
|
|
3
|
+
module Txt
|
|
4
|
+
|
|
5
|
+
class LinesSerializer < TxtSerializer
|
|
6
|
+
DEFAULT_NEWLINE_SEPARATOR = "\n"
|
|
7
|
+
|
|
8
|
+
attr_reader :newline_separator, :lines
|
|
9
|
+
|
|
10
|
+
def initialize(stream, locale, options = {})
|
|
11
|
+
@newline_separator = options.fetch(:newline_separator, DEFAULT_NEWLINE_SEPARATOR)
|
|
12
|
+
@lines = []
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def write_key_value(key, value)
|
|
17
|
+
unless valid_key?(key)
|
|
18
|
+
raise KeyError, "'#{key}' is not a valid key"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
add_line(key, value)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def flush
|
|
25
|
+
stream.write(lines.join(newline_separator))
|
|
26
|
+
super
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def add_line(key, value)
|
|
32
|
+
key = parse_key(key)
|
|
33
|
+
|
|
34
|
+
if key >= lines.size
|
|
35
|
+
lines.concat(Array.new(key - lines.size + 1) { '' })
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
lines[key] = value
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def parse_key(key)
|
|
42
|
+
key.to_i
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def valid_key?(key)
|
|
46
|
+
!!(key =~ /[\d]+/)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/abroad/version.rb
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
include Abroad::Extractors
|
|
4
|
+
|
|
5
|
+
describe Txt::LinesExtractor do
|
|
6
|
+
it 'extracts text into lines' do
|
|
7
|
+
text = outdent(%Q(
|
|
8
|
+
foo
|
|
9
|
+
|
|
10
|
+
bar
|
|
11
|
+
|
|
12
|
+
baz
|
|
13
|
+
boo
|
|
14
|
+
))
|
|
15
|
+
|
|
16
|
+
strings = described_class.from_string(text).extract_each.to_a
|
|
17
|
+
|
|
18
|
+
expect(strings).to eq([
|
|
19
|
+
['0', 'foo'], ['1', ''], ['2', 'bar'],
|
|
20
|
+
['3', ''], ['4', 'baz'], ['5', 'boo']
|
|
21
|
+
])
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
include Abroad::Serializers
|
|
4
|
+
|
|
5
|
+
describe Txt::LinesSerializer do
|
|
6
|
+
let(:stream) { StringIO.new }
|
|
7
|
+
let(:locale) { 'en' }
|
|
8
|
+
let(:serializer) { described_class.from_stream(stream, locale) }
|
|
9
|
+
|
|
10
|
+
it 'writes key/value pairs' do
|
|
11
|
+
serializer.write_key_value('2', 'foo')
|
|
12
|
+
serializer.write_key_value('3', 'bar')
|
|
13
|
+
serializer.write_key_value('5', 'baz')
|
|
14
|
+
|
|
15
|
+
serializer.close
|
|
16
|
+
expect(stream.string).to eq(outdent(%Q(
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
foo
|
|
20
|
+
bar
|
|
21
|
+
|
|
22
|
+
baz
|
|
23
|
+
)).rstrip)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'raises an error if given a non-numeric key' do
|
|
27
|
+
expect { serializer.write_key_value('abc', 'def') }.to(
|
|
28
|
+
raise_error(KeyError)
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -4,10 +4,19 @@ require 'rspec'
|
|
|
4
4
|
require 'abroad'
|
|
5
5
|
require 'yaml'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
def
|
|
9
|
-
|
|
7
|
+
module SpecHelpers
|
|
8
|
+
def outdent(str)
|
|
9
|
+
# The special YAML pipe operator treats the text that follows as literal,
|
|
10
|
+
# and includes newlines, tabs, and spaces. It also strips leading tabs and
|
|
11
|
+
# spaces. This means you can include a fully indented bit of, say, source
|
|
12
|
+
# code in your source code, and it will give you back a string with all the
|
|
13
|
+
# indentation preserved (but without any leading indentation).
|
|
14
|
+
YAML.load("|#{str}")
|
|
10
15
|
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
RSpec.configure do |config|
|
|
19
|
+
config.include(SpecHelpers)
|
|
11
20
|
|
|
12
21
|
shared_examples 'a fixture-based extractor' do |dir, namespace|
|
|
13
22
|
fixture_manifest = YAML.load_file(File.join(dir, 'fixtures.yml'))
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: abroad
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cameron Dutro
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: htmlentities
|
|
@@ -109,6 +109,9 @@ files:
|
|
|
109
109
|
- lib/abroad/extractors/json.rb
|
|
110
110
|
- lib/abroad/extractors/json/json_extractor.rb
|
|
111
111
|
- lib/abroad/extractors/json/key_value_extractor.rb
|
|
112
|
+
- lib/abroad/extractors/txt.rb
|
|
113
|
+
- lib/abroad/extractors/txt/lines_extractor.rb
|
|
114
|
+
- lib/abroad/extractors/txt/txt_extractor.rb
|
|
112
115
|
- lib/abroad/extractors/xml.rb
|
|
113
116
|
- lib/abroad/extractors/xml/android_extractor.rb
|
|
114
117
|
- lib/abroad/extractors/xml/xml_extractor.rb
|
|
@@ -123,6 +126,9 @@ files:
|
|
|
123
126
|
- lib/abroad/serializers/json/key_value_serializer.rb
|
|
124
127
|
- lib/abroad/serializers/serializer.rb
|
|
125
128
|
- lib/abroad/serializers/trie.rb
|
|
129
|
+
- lib/abroad/serializers/txt.rb
|
|
130
|
+
- lib/abroad/serializers/txt/lines_serializer.rb
|
|
131
|
+
- lib/abroad/serializers/txt/txt_serializer.rb
|
|
126
132
|
- lib/abroad/serializers/xml.rb
|
|
127
133
|
- lib/abroad/serializers/xml/android_serializer.rb
|
|
128
134
|
- lib/abroad/serializers/xml/xml_serializer.rb
|
|
@@ -138,6 +144,7 @@ files:
|
|
|
138
144
|
- spec/extractors/json/fixtures/basic.json
|
|
139
145
|
- spec/extractors/json/fixtures/objects.json
|
|
140
146
|
- spec/extractors/json/json_extractor_spec.rb
|
|
147
|
+
- spec/extractors/txt/lines_extractor_spec.rb
|
|
141
148
|
- spec/extractors/xml/fixtures.yml
|
|
142
149
|
- spec/extractors/xml/fixtures/basic_arrays.xml
|
|
143
150
|
- spec/extractors/xml/fixtures/basic_plurals.xml
|
|
@@ -159,6 +166,7 @@ files:
|
|
|
159
166
|
- spec/extractors/yaml/jruby_compat_spec.rb
|
|
160
167
|
- spec/extractors/yaml/yaml_extractor_spec.rb
|
|
161
168
|
- spec/serializers/json/key_value_serializer_spec.rb
|
|
169
|
+
- spec/serializers/txt/lines_serializer_spec.rb
|
|
162
170
|
- spec/serializers/xml/android_serializer_spec.rb
|
|
163
171
|
- spec/serializers/yaml/rails_serializer_spec.rb
|
|
164
172
|
- spec/spec_helper.rb
|
|
@@ -181,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
181
189
|
version: '0'
|
|
182
190
|
requirements: []
|
|
183
191
|
rubyforge_project:
|
|
184
|
-
rubygems_version: 2.
|
|
192
|
+
rubygems_version: 2.2.5
|
|
185
193
|
signing_key:
|
|
186
194
|
specification_version: 4
|
|
187
195
|
summary: A set of parsers and serializers for dealing with localization file formats.
|