clausewitz-spelling 0.2.16 → 0.2.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daaea52183455f6976867e87c55de6a3c3394d912d48e93a9a494655feddf81a
4
- data.tar.gz: d090c2311b22670354bed6bdf1055bd610ef46b57f46ff02f7b99deb182f3a65
3
+ metadata.gz: c7068d2ed59ef6a208ee2f18e86e1ba32d824065b1cec88654ea59f3b689d998
4
+ data.tar.gz: 141d5a09103f95f44415d4d65c464485c6187fec964e448ca26c67322f77b5ca
5
5
  SHA512:
6
- metadata.gz: ba7d277f9e4bfe7f173a730d4ae60249244afe8decdbfb2540bc9e79497444ba036f474545f65062f76ca4354882fb85499bf185e26db337b2fbf577d58e9daf
7
- data.tar.gz: 11fa5ccd399dae5558a231620c2ca54f2aaa0b9957ccbafbcd021250d0c89f9a62e66c29fca70319589ad279aac6d6e8e979aeeb8a89d478b8415e2824b9288e
6
+ metadata.gz: 1201a42008e483b88ecd89e3dc826385f546a3000576a4121c520f9b8cea4286c90dfe3ca534d6f76e732c5eed0076940f14e033fc6e59dab635b21a622df5c2
7
+ data.tar.gz: 3355650f99636c77df5a84ecfaec6010d3ea049591f09310e67af4dbb44b4847013fcb03d27ec1d5b22540537529c77df58975433cd6450296d8876feb36ef24
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clausewitz-spelling (0.2.16)
4
+ clausewitz-spelling (0.2.17)
5
5
  colorize
6
6
  damerau-levenshtein
7
7
  ffi-hunspell-wtchappell
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'yaml'
2
4
 
3
5
  module Clausewitz
@@ -53,10 +55,18 @@ module Clausewitz
53
55
  'german',
54
56
  'de', %w[de], 'de'
55
57
  ),
56
- 'l_portuguese' => LangConfig.new(
57
- 'portuguese',
58
- 'pt', %w[pt br], 'pt'
58
+ 'l_polish' => LangConfig.new(
59
+ 'polish',
60
+ 'pl', %w[pl], 'pl'
61
+ ),
62
+ 'l_braz_por' => LangConfig.new(
63
+ 'braz_por',
64
+ 'pt', %w[br], 'br'
59
65
  ),
66
+ #'l_portuguese' => LangConfig.new(
67
+ # 'portuguese',
68
+ # 'pt', %w[br pt], 'pt'
69
+ #),
60
70
  'l_spanish' => LangConfig.new(
61
71
  'spanish',
62
72
  'es', %w[mx es], 'es'
@@ -69,18 +79,27 @@ module Clausewitz
69
79
 
70
80
  def self.parse(text)
71
81
  self.pre_validate(text)
72
- smudged_text = text.lines.map do |line|
73
- self.smudge_key(line)
74
- end
75
- contents = YAML.load(smudged_text.join("\n"))
76
- self.validate_localisation!(contents)
77
- contents.each do |lang, entries|
78
- entry_keys = entries ? entries.keys : []
79
- entry_keys.each do |key|
80
- entries[unsmudge_key(key)] = entries.delete(key)
82
+ contents = {}
83
+ current_lang = nil
84
+ text.lines.each do |line|
85
+ line.strip!
86
+ next if line.empty? || line =~ /^#/
87
+ lang_match = LANG_MAP.keys.find { |lang| line == "#{lang}:" }
88
+ if lang_match
89
+ current_lang = lang_match
90
+ next
91
+ end
92
+ unless current_lang
93
+ errors = ["Cannot parse loc key without a langauge being set!"]
94
+ fail(UnparseableFileError, errors)
81
95
  end
96
+ key, value = line.split(/\s/, 2)
97
+ key.gsub!(/:(\d+)?$/, '')
98
+ value.gsub!(/(^"|"$)/, '')
99
+ contents[current_lang] ||= {}
100
+ contents[current_lang][key] = value
82
101
  end
83
- contents
102
+ return contents
84
103
  end
85
104
 
86
105
  def self.pre_validate(text)
@@ -88,11 +107,6 @@ module Clausewitz
88
107
  text.lines[1..-1].each_with_index do |line, index|
89
108
  lineno = index + 2
90
109
 
91
-
92
- if line =~ /^\s*([\w\d.'-])+\:([0-9]+)? \"/ && line !~ /^ ([\w\d.'-])+\:([0-9]+)? \"/
93
- errors << "Line ##{lineno} does not start with two spaces."
94
- end
95
-
96
110
  if line =~ /^\s*([\w\d.'-])+\:([0-9]+)?\"/
97
111
  errors << "Line ##{lineno} is missing a space between the key and value."
98
112
  end
@@ -100,32 +114,18 @@ module Clausewitz
100
114
  if line.count('"').odd?
101
115
  errors << "Unmatched double quote on line ##{lineno}."
102
116
  end
103
-
104
- quote_pxs = (0 ... line.length).find_all { |i| line[i, 1] == '"' }
105
- quote_pxs.shift; quote_pxs.pop;
106
- if quote_pxs.any? { |px| line[px - 1] != '\\' }
107
- errors << "Unescaped double quote on line ##{lineno}."
108
- end
109
117
  end
110
118
  fail(UnparseableFileError, errors) unless errors.empty?
111
119
  end
112
120
 
113
121
  def self.parse_file(filepath)
114
122
  contents = nil
115
- File.open(filepath, 'r:UTF-8') do |f|
123
+ File.open(filepath, 'r:bom|UTF-8') do |f|
116
124
  contents = f.read
117
125
  end
118
126
  self.parse(contents)
119
127
  end
120
128
 
121
- def self.smudge_key(line)
122
- if line =~ / ([\w\d.'-])+\:([0-9]+) \"/
123
- line.sub(/\:([0-9]+) /, '!!!\1: ')
124
- else
125
- line
126
- end
127
- end
128
-
129
129
  def self.validate_localisation!(contents)
130
130
  fail("Unknown language keys!") unless contents.keys.all? do |lang|
131
131
  self.valid_lang?(lang)
@@ -136,9 +136,5 @@ module Clausewitz
136
136
  def self.valid_lang?(lang)
137
137
  lang =~ VALID_LANG_REGEX
138
138
  end
139
-
140
- def self.unsmudge_key(line)
141
- line.sub(/!!!([0-9]+)$/, ':\1')
142
- end
143
139
  end
144
140
  end
@@ -9,6 +9,9 @@ require 'pragmatic_tokenizer'
9
9
  require 'clausewitz/localisation'
10
10
  require 'clausewitz/spelling/results'
11
11
 
12
+ require 'pp'
13
+ pp FFI::Hunspell.directories
14
+
12
15
  module Clausewitz; module Spelling
13
16
  class Checker
14
17
  DEFAULT_SUGGESTION_COUNT = 3
@@ -164,6 +167,8 @@ module Clausewitz; module Spelling
164
167
  punctuation: :none,
165
168
  downcase: false
166
169
  }
170
+ entry.gsub!('\n', ' ')
171
+ entry.gsub!('\"', '"')
167
172
  words = PragmaticTokenizer::Tokenizer.new(opts).tokenize(entry)
168
173
  words = words.map { |word| word.split('—') }.flatten(1)
169
174
  words.map! do |word|
@@ -142,7 +142,7 @@ module Clausewitz; module Spelling
142
142
  if failed?
143
143
  outlines = @word_results.map { |w| "#{spacer}#{w.to_str(indent + 2)}" }
144
144
  outlines = outlines.join("\n")
145
- "#{spacer}#{@key.red}\n#{outlines}"
145
+ "#{spacer}#{@key.red}:\n#{outlines}"
146
146
  else
147
147
  "#{spacer}#{@key} passed".green
148
148
  end
@@ -214,7 +214,7 @@ module Clausewitz; module Spelling
214
214
  msg = "#{spacer}#{@word}".red
215
215
 
216
216
  if @suggestions && !@suggestions.empty?
217
- msg += " (#{@suggestions.join(', ')})".yellow
217
+ msg += " (#{@suggestions.map { |sug| sug.encode('utf-8') }.join(', ')})".yellow
218
218
  else
219
219
  msg += " (-- no suggestions --)".yellow
220
220
  end
@@ -1,5 +1,5 @@
1
1
  module Clausewitz
2
2
  module Spelling
3
- VERSION = "0.2.16"
3
+ VERSION = "0.2.17"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clausewitz-spelling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Chappell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-07 00:00:00.000000000 Z
11
+ date: 2019-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -157,7 +157,6 @@ files:
157
157
  - bin/console
158
158
  - bin/setup
159
159
  - clausewitz-spelling.gemspec
160
- - en_GB_owb.dic
161
160
  - exe/clausewitz-spellcheck
162
161
  - lib/clausewitz/localisation.rb
163
162
  - lib/clausewitz/spelling.rb
@@ -1,81 +0,0 @@
1
- 35
2
- Adytum/1
3
- Almirante/1
4
- APC/2 1
5
- Allgood/1
6
- Aradesh/1
7
- Bearport/1
8
- Boneyard/1
9
- Chico/1
10
- Ciudad/1
11
- Colibrí/1
12
- Darkwater/1
13
- Dayglow/1
14
- Elijah/1
15
- Elijah's
16
- FEV/1
17
- GAI/1
18
- Gizmo/1
19
- Harbor/1
20
- Hardin/2 1
21
- Hardin's
22
- Harlon/1
23
- Héctor/1
24
- Henderton/1
25
- Hubology
26
- Hubologist/2 1
27
- Junktown/1
28
- Klamath/1
29
- Los
30
- Maxson/1
31
- Morbid/1
32
- Mossman/1
33
- NCR/1
34
- Paz/1
35
- Pesca/1
36
- Peterson/1
37
- Petro/1
38
- Rafael/1
39
- Rattletail/1
40
- Reynosa/1
41
- RobCo/1
42
- Santángel/1
43
- Seabear/1
44
- Shi/1
45
- Silus/1
46
- Tamaulipas/1
47
- Tampico/1
48
- Tandi/1
49
- Tech
50
- Tlaloc/1
51
- TODO/1
52
- West-Tek/1
53
- Valles/1
54
- Vandenberg/1
55
- Vault-Tec/1
56
- bandito/2 1
57
- brahmin/5 1
58
- caudillo/2 1
59
- commonfolk/5 1
60
- deathclaw/2 1
61
- doodad/2 1
62
- eyebot/2
63
- firefight/2 1
64
- firepower/5 1
65
- hardline/2 1
66
- lakebed/2 1
67
- malcontents
68
- military's
69
- playbook/2 1
70
- protectron/2 1
71
- radscorpion/2 1
72
- robobrain/2 1
73
- securitron/2 1
74
- shopfront/2 1
75
- superweapon/2 1
76
- tribals/5 1
77
- underway
78
- unpowered
79
- vertibird/2 1
80
- weaponsmith/2 1
81
- wildcard/2 1