code-pages 1.0.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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/Rakefile +24 -0
  4. data/code-pages.gemspec +18 -0
  5. data/lib/code-pages.rb +1 -0
  6. data/lib/code-pages/code_page.rb +20 -0
  7. data/lib/code-pages/importer.rb +67 -0
  8. data/lib/code-pages/version.rb +3 -0
  9. data/lib/code_pages.rb +38 -0
  10. data/resources/10000.yml +256 -0
  11. data/resources/10006.yml +256 -0
  12. data/resources/10007.yml +257 -0
  13. data/resources/10029.yml +257 -0
  14. data/resources/10079.yml +256 -0
  15. data/resources/10081.yml +255 -0
  16. data/resources/1026.yml +257 -0
  17. data/resources/1250.yml +252 -0
  18. data/resources/1251.yml +256 -0
  19. data/resources/1252.yml +252 -0
  20. data/resources/1253.yml +240 -0
  21. data/resources/1254.yml +250 -0
  22. data/resources/1255.yml +234 -0
  23. data/resources/1256.yml +257 -0
  24. data/resources/1257.yml +245 -0
  25. data/resources/1258.yml +248 -0
  26. data/resources/28591.yml +257 -0
  27. data/resources/28592.yml +257 -0
  28. data/resources/28593.yml +250 -0
  29. data/resources/28594.yml +257 -0
  30. data/resources/28595.yml +257 -0
  31. data/resources/28596.yml +212 -0
  32. data/resources/28597.yml +254 -0
  33. data/resources/28598.yml +221 -0
  34. data/resources/28599.yml +257 -0
  35. data/resources/28600.yml +257 -0
  36. data/resources/28601.yml +249 -0
  37. data/resources/28603.yml +257 -0
  38. data/resources/28604.yml +257 -0
  39. data/resources/28605.yml +257 -0
  40. data/resources/28606.yml +257 -0
  41. data/resources/37.yml +257 -0
  42. data/resources/437.yml +257 -0
  43. data/resources/47451.yml +257 -0
  44. data/resources/500.yml +257 -0
  45. data/resources/737.yml +257 -0
  46. data/resources/775.yml +257 -0
  47. data/resources/850.yml +257 -0
  48. data/resources/852.yml +257 -0
  49. data/resources/855.yml +257 -0
  50. data/resources/857.yml +254 -0
  51. data/resources/860.yml +257 -0
  52. data/resources/861.yml +257 -0
  53. data/resources/862.yml +257 -0
  54. data/resources/863.yml +257 -0
  55. data/resources/864.yml +251 -0
  56. data/resources/865.yml +257 -0
  57. data/resources/866.yml +257 -0
  58. data/resources/869.yml +248 -0
  59. data/resources/874.yml +226 -0
  60. data/resources/875.yml +257 -0
  61. data/resources/932.yml +7916 -0
  62. data/resources/936.yml +21921 -0
  63. data/resources/949.yml +17177 -0
  64. data/resources/950.yml +13632 -0
  65. data/resources/code_page_manifest.yml +110 -0
  66. data/spec/code_page_spec.rb +22 -0
  67. data/spec/code_pages_spec.rb +49 -0
  68. data/spec/spec_helper.rb +8 -0
  69. metadata +110 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a666cbacc1bdb0ef5d453d63598d65db0d76ef5d
4
+ data.tar.gz: 0bd3052e4ef28c7c51374c7459a63cc6331ec7e6
5
+ SHA512:
6
+ metadata.gz: 0734705ccfef3a5fa24064cc6c00622f5a62807955fe70fe61313494c272e267ca1f2d2a8ef821dba44e373224e66c0c6204dd82ad824a33c6f0967e1d654a3c
7
+ data.tar.gz: 3e07d38166ae28d53bf84903d65fb3cfb594ba914addd10009ba76790931a6616baa8fe3f34c5c53bd2558721c3dd57954a343f01ecc0e46f98504ed939ec44b
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'pry-byebug'
7
+ gem 'rake'
8
+ gem 'rspec', '~> 3.0'
9
+ end
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+
3
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
4
+
5
+ require 'bundler'
6
+ require 'pry-byebug'
7
+ require 'rspec/core/rake_task'
8
+ require 'rubygems/package_task'
9
+ require 'code-pages'
10
+
11
+ Bundler::GemHelper.install_tasks
12
+
13
+ task default: :spec
14
+
15
+ desc 'Run specs'
16
+ RSpec::Core::RakeTask.new do |t|
17
+ t.pattern = './spec/**/*_spec.rb'
18
+ end
19
+
20
+ task :import do
21
+ CodePages::Importer.import(
22
+ CodePages.manifest, File.expand_path('../resources', __FILE__)
23
+ )
24
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+ require 'code-pages/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'code-pages'
6
+ s.version = ::CodePages::VERSION
7
+ s.authors = ['Cameron Dutro']
8
+ s.email = ['camertron@gmail.com']
9
+ s.homepage = 'http://github.com/camertron/code-pages'
10
+
11
+ s.description = s.summary = 'A database of legacy Microsoft and ISO 8859 code pages for Ruby.'
12
+
13
+ s.platform = Gem::Platform::RUBY
14
+ s.has_rdoc = true
15
+
16
+ s.require_path = 'lib'
17
+ s.files = Dir['{lib,spec,resources}/**/*', 'Gemfile', 'README.md', 'Rakefile', 'code-pages.gemspec']
18
+ end
data/lib/code-pages.rb ADDED
@@ -0,0 +1 @@
1
+ require 'code_pages'
@@ -0,0 +1,20 @@
1
+ require 'yaml'
2
+
3
+ module CodePages
4
+ class CodePage
5
+ attr_reader :id, :resource_file
6
+
7
+ def initialize(id, resource_file)
8
+ @id = id
9
+ @resource_file = resource_file
10
+ end
11
+
12
+ def to_utf8(str)
13
+ str.each_byte.map { |byte| unicode_mapping[byte] }.pack('U*')
14
+ end
15
+
16
+ def unicode_mapping
17
+ @unicode_mapping ||= YAML.load_file(resource_file)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,67 @@
1
+ require 'open-uri'
2
+ require 'yaml'
3
+
4
+ module CodePages
5
+ class Importer
6
+ def self.import(manifest, output_path)
7
+ new(manifest, output_path).import
8
+ end
9
+
10
+ attr_reader :manifest, :output_path
11
+
12
+ def initialize(manifest, output_path)
13
+ @manifest = manifest
14
+ @output_path = output_path
15
+ end
16
+
17
+ def import
18
+ manifest.each do |props|
19
+ STDOUT.write("Importing #{props['code_page']}... ")
20
+ import_code_page(props)
21
+ puts 'done.'
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def import_code_page(props)
28
+ output_file = File.join(output_path, "#{props['code_page']}.yml")
29
+ code_page = get_code_page(props['url'])
30
+ File.write(output_file, YAML.dump(code_page))
31
+ end
32
+
33
+ def get_code_page(url)
34
+ io = open(url)
35
+
36
+ {}.tap do |code_page|
37
+ parse_resource(io) do |line|
38
+ next if (line[1] || '').empty?
39
+ code_page[hex2dec(line[0])] = hex2dec(line[1])
40
+ break if line[0].upcase == '0XFF'
41
+ end
42
+ end
43
+ end
44
+
45
+ def hex2dec(hex_str)
46
+ hex_str[2..-1].to_i(16)
47
+ end
48
+
49
+ def parse_resource(io)
50
+ io.each_line do |line|
51
+ unless line[0] == '#'
52
+ comment_idx = if idx = line.index('#')
53
+ idx - 1 # consume #
54
+ else
55
+ line.size
56
+ end
57
+
58
+ line = line.chomp[0..comment_idx]
59
+
60
+ if line.size > 0
61
+ yield line.split("\t", -1).map(&:strip)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module CodePages
2
+ VERSION = '1.0.0'
3
+ end
data/lib/code_pages.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'yaml'
2
+
3
+ module CodePages
4
+ autoload :CodePage, 'code-pages/code_page'
5
+ autoload :Importer, 'code-pages/importer'
6
+
7
+ class << self
8
+ def [](index)
9
+ all[index]
10
+ end
11
+
12
+ def supported_ids
13
+ @supported_ids ||= all.keys
14
+ end
15
+
16
+ def supports?(id)
17
+ supported_ids.include?(id)
18
+ end
19
+
20
+ def all
21
+ @all ||= manifest.each_with_object({}) do |props, ret|
22
+ ret[props['code_page']] = CodePage.new(
23
+ props['code_page'], File.join(resources_dir, "#{props['code_page']}.yml")
24
+ )
25
+ end
26
+ end
27
+
28
+ def manifest
29
+ @manifest ||= YAML.load_file(
30
+ File.join(resources_dir, 'code_page_manifest.yml')
31
+ )
32
+ end
33
+
34
+ def resources_dir
35
+ @resources_dir ||= File.expand_path('../../resources', __FILE__)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,256 @@
1
+ ---
2
+ 0: 0
3
+ 1: 1
4
+ 2: 2
5
+ 3: 3
6
+ 4: 4
7
+ 5: 5
8
+ 6: 6
9
+ 7: 7
10
+ 8: 8
11
+ 9: 9
12
+ 10: 10
13
+ 11: 11
14
+ 12: 12
15
+ 13: 13
16
+ 14: 14
17
+ 15: 15
18
+ 16: 16
19
+ 17: 17
20
+ 18: 18
21
+ 19: 19
22
+ 20: 20
23
+ 21: 21
24
+ 22: 22
25
+ 23: 23
26
+ 24: 24
27
+ 25: 25
28
+ 26: 26
29
+ 27: 27
30
+ 28: 28
31
+ 29: 29
32
+ 30: 30
33
+ 31: 31
34
+ 32: 32
35
+ 33: 33
36
+ 34: 34
37
+ 35: 35
38
+ 36: 36
39
+ 37: 37
40
+ 38: 38
41
+ 39: 39
42
+ 40: 40
43
+ 41: 41
44
+ 42: 42
45
+ 43: 43
46
+ 44: 44
47
+ 45: 45
48
+ 46: 46
49
+ 47: 47
50
+ 48: 48
51
+ 49: 49
52
+ 50: 50
53
+ 51: 51
54
+ 52: 52
55
+ 53: 53
56
+ 54: 54
57
+ 55: 55
58
+ 56: 56
59
+ 57: 57
60
+ 58: 58
61
+ 59: 59
62
+ 60: 60
63
+ 61: 61
64
+ 62: 62
65
+ 63: 63
66
+ 64: 64
67
+ 65: 65
68
+ 66: 66
69
+ 67: 67
70
+ 68: 68
71
+ 69: 69
72
+ 70: 70
73
+ 71: 71
74
+ 72: 72
75
+ 73: 73
76
+ 74: 74
77
+ 75: 75
78
+ 76: 76
79
+ 77: 77
80
+ 78: 78
81
+ 79: 79
82
+ 80: 80
83
+ 81: 81
84
+ 82: 82
85
+ 83: 83
86
+ 84: 84
87
+ 85: 85
88
+ 86: 86
89
+ 87: 87
90
+ 88: 88
91
+ 89: 89
92
+ 90: 90
93
+ 91: 91
94
+ 92: 92
95
+ 93: 93
96
+ 94: 94
97
+ 95: 95
98
+ 96: 96
99
+ 97: 97
100
+ 98: 98
101
+ 99: 99
102
+ 100: 100
103
+ 101: 101
104
+ 102: 102
105
+ 103: 103
106
+ 104: 104
107
+ 105: 105
108
+ 106: 106
109
+ 107: 107
110
+ 108: 108
111
+ 109: 109
112
+ 110: 110
113
+ 111: 111
114
+ 112: 112
115
+ 113: 113
116
+ 114: 114
117
+ 115: 115
118
+ 116: 116
119
+ 117: 117
120
+ 118: 118
121
+ 119: 119
122
+ 120: 120
123
+ 121: 121
124
+ 122: 122
125
+ 123: 123
126
+ 124: 124
127
+ 125: 125
128
+ 126: 126
129
+ 127: 127
130
+ 128: 196
131
+ 129: 197
132
+ 130: 199
133
+ 131: 201
134
+ 132: 209
135
+ 133: 214
136
+ 134: 220
137
+ 135: 225
138
+ 136: 224
139
+ 137: 226
140
+ 138: 228
141
+ 139: 227
142
+ 140: 229
143
+ 141: 231
144
+ 142: 233
145
+ 143: 232
146
+ 144: 234
147
+ 145: 235
148
+ 146: 237
149
+ 147: 236
150
+ 148: 238
151
+ 149: 239
152
+ 150: 241
153
+ 151: 243
154
+ 152: 242
155
+ 153: 244
156
+ 154: 246
157
+ 155: 245
158
+ 156: 250
159
+ 157: 249
160
+ 158: 251
161
+ 159: 252
162
+ 160: 8224
163
+ 161: 176
164
+ 162: 162
165
+ 163: 163
166
+ 164: 167
167
+ 165: 8226
168
+ 166: 182
169
+ 167: 223
170
+ 168: 174
171
+ 169: 169
172
+ 170: 8482
173
+ 171: 180
174
+ 172: 168
175
+ 173: 8800
176
+ 174: 198
177
+ 175: 216
178
+ 176: 8734
179
+ 177: 177
180
+ 178: 8804
181
+ 179: 8805
182
+ 180: 165
183
+ 181: 181
184
+ 182: 8706
185
+ 183: 8721
186
+ 184: 8719
187
+ 185: 960
188
+ 186: 8747
189
+ 187: 170
190
+ 188: 186
191
+ 189: 8486
192
+ 190: 230
193
+ 191: 248
194
+ 192: 191
195
+ 193: 161
196
+ 194: 172
197
+ 195: 8730
198
+ 196: 402
199
+ 197: 8776
200
+ 198: 8710
201
+ 199: 171
202
+ 200: 187
203
+ 201: 8230
204
+ 202: 160
205
+ 203: 192
206
+ 204: 195
207
+ 205: 213
208
+ 206: 338
209
+ 207: 339
210
+ 208: 8211
211
+ 209: 8212
212
+ 210: 8220
213
+ 211: 8221
214
+ 212: 8216
215
+ 213: 8217
216
+ 214: 247
217
+ 215: 9674
218
+ 216: 255
219
+ 217: 376
220
+ 218: 8260
221
+ 219: 164
222
+ 220: 8249
223
+ 221: 8250
224
+ 222: 64257
225
+ 223: 64258
226
+ 224: 8225
227
+ 225: 183
228
+ 226: 8218
229
+ 227: 8222
230
+ 228: 8240
231
+ 229: 194
232
+ 230: 202
233
+ 231: 193
234
+ 232: 203
235
+ 233: 200
236
+ 234: 205
237
+ 235: 206
238
+ 236: 207
239
+ 237: 204
240
+ 238: 211
241
+ 239: 212
242
+ 241: 210
243
+ 242: 218
244
+ 243: 219
245
+ 244: 217
246
+ 245: 305
247
+ 246: 710
248
+ 247: 732
249
+ 248: 175
250
+ 249: 728
251
+ 250: 729
252
+ 251: 730
253
+ 252: 184
254
+ 253: 733
255
+ 254: 731
256
+ 255: 711