html_number_decoder 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b57caa2bb7077f0d67796d64f1c0f02171fc1f2e
4
+ data.tar.gz: 3a062ce0acbdd897f3e3a0d49b471853af7a4fb3
5
+ SHA512:
6
+ metadata.gz: 6b720e3589b8d1a9ce20fbffa797e7d08112e1ccd6f05f45d203ea3ec7383a28207b1f2dc9d20b82410f79e6a9a9e94769b1eec6e8f6622bbf499cf31f7723cd
7
+ data.tar.gz: 544b65a20c8228dc14f6e93d0313669812715fa71482f1f21d6955d708c19ad20d191b8de5c5c6037597924047fa2f3c184705b7b72b783ff3d1ee44a69af743
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ html_number_decoder-*
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # HTML Number Decoder
2
+
3
+ This gem is solely focused on decoding HTML Numbers in the form of ` `.
4
+
5
+ You can see a full table of HTML Numbers here: http://www.ascii.cl/htmlcodes.htm
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ gem install html_number_decoder
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ string = "how's it going pal?"
17
+ HtmlNumberDecoder.decode(string) #=> "how's it going pal?"
18
+ ```
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "html_number_decoder/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "html_number_decoder"
8
+ spec.version = HtmlNumberDecoder::VERSION
9
+ spec.authors = ["Eli Fatsi"]
10
+ spec.email = ["eli.fatsi@viget.com"]
11
+
12
+ spec.summary = "Decode HTML Numbers into characters"
13
+ spec.homepage = "https://github.com/efatsi/html_number_decoder"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,213 @@
1
+ MAPPING = {
2
+ "32" => " ",
3
+ "33" => "!",
4
+ "34" => "\"",
5
+ "35" => "#",
6
+ "36" => "$",
7
+ "37" => "%",
8
+ "38" => "&",
9
+ "39" => "'",
10
+ "40" => "(",
11
+ "41" => ")",
12
+ "42" => "*",
13
+ "43" => "+",
14
+ "44" => ",",
15
+ "45" => "-",
16
+ "46" => ".",
17
+ "47" => "/",
18
+ "48" => "0",
19
+ "49" => "1",
20
+ "50" => "2",
21
+ "51" => "3",
22
+ "52" => "4",
23
+ "53" => "5",
24
+ "54" => "6",
25
+ "55" => "7",
26
+ "56" => "8",
27
+ "57" => "9",
28
+ "58" => ":",
29
+ "59" => ";",
30
+ "60" => "<",
31
+ "61" => "=",
32
+ "62" => ">",
33
+ "63" => "?",
34
+ "64" => "@",
35
+ "65" => "A",
36
+ "66" => "B",
37
+ "67" => "C",
38
+ "68" => "D",
39
+ "69" => "E",
40
+ "70" => "F",
41
+ "71" => "G",
42
+ "72" => "H",
43
+ "73" => "I",
44
+ "74" => "J",
45
+ "75" => "K",
46
+ "76" => "L",
47
+ "77" => "M",
48
+ "78" => "N",
49
+ "79" => "O",
50
+ "80" => "P",
51
+ "81" => "Q",
52
+ "82" => "R",
53
+ "83" => "S",
54
+ "84" => "T",
55
+ "85" => "U",
56
+ "86" => "V",
57
+ "87" => "W",
58
+ "88" => "X",
59
+ "89" => "Y",
60
+ "90" => "Z",
61
+ "91" => "[",
62
+ "92" => "\\",
63
+ "93" => "]",
64
+ "94" => "^",
65
+ "95" => "_",
66
+ "96" => "`",
67
+ "97" => "a",
68
+ "98" => "b",
69
+ "99" => "c",
70
+ "100" => "d",
71
+ "101" => "e",
72
+ "102" => "f",
73
+ "103" => "g",
74
+ "104" => "h",
75
+ "105" => "i",
76
+ "106" => "j",
77
+ "107" => "k",
78
+ "108" => "l",
79
+ "109" => "m",
80
+ "110" => "n",
81
+ "111" => "o",
82
+ "112" => "p",
83
+ "113" => "q",
84
+ "114" => "r",
85
+ "115" => "s",
86
+ "116" => "t",
87
+ "117" => "u",
88
+ "118" => "v",
89
+ "119" => "w",
90
+ "120" => "x",
91
+ "121" => "y",
92
+ "122" => "z",
93
+ "123" => "{",
94
+ "124" => "|",
95
+ "125" => "}",
96
+ "126" => "~",
97
+ "160" => " ",
98
+ "161" => "¡",
99
+ "162" => "¢",
100
+ "163" => "£",
101
+ "164" => "¤",
102
+ "165" => "¥",
103
+ "166" => "¦",
104
+ "167" => "§",
105
+ "168" => "¨",
106
+ "169" => "©",
107
+ "170" => "ª",
108
+ "171" => "«",
109
+ "172" => "¬",
110
+ "174" => "®",
111
+ "175" => "¯",
112
+ "176" => "°",
113
+ "177" => "±",
114
+ "178" => "²",
115
+ "179" => "³",
116
+ "180" => "´",
117
+ "181" => "µ",
118
+ "182" => "¶",
119
+ "183" => "·",
120
+ "184" => "¸",
121
+ "185" => "¹",
122
+ "186" => "º",
123
+ "187" => "»",
124
+ "188" => "¼",
125
+ "189" => "½",
126
+ "190" => "¾",
127
+ "191" => "¿",
128
+ "192" => "À",
129
+ "193" => "Á",
130
+ "194" => "Â",
131
+ "195" => "Ã",
132
+ "196" => "Ä",
133
+ "197" => "Å",
134
+ "198" => "Æ",
135
+ "199" => "Ç",
136
+ "200" => "È",
137
+ "201" => "É",
138
+ "202" => "Ê",
139
+ "203" => "Ë",
140
+ "204" => "Ì",
141
+ "205" => "Í",
142
+ "206" => "Î",
143
+ "207" => "Ï",
144
+ "208" => "Ð",
145
+ "209" => "Ñ",
146
+ "210" => "Ò",
147
+ "211" => "Ó",
148
+ "212" => "Ô",
149
+ "213" => "Õ",
150
+ "214" => "Ö",
151
+ "215" => "×",
152
+ "216" => "Ø",
153
+ "217" => "Ù",
154
+ "218" => "Ú",
155
+ "219" => "Û",
156
+ "220" => "Ü",
157
+ "221" => "Ý",
158
+ "222" => "Þ",
159
+ "223" => "ß",
160
+ "224" => "à",
161
+ "225" => "á",
162
+ "226" => "â",
163
+ "227" => "ã",
164
+ "228" => "ä",
165
+ "229" => "å",
166
+ "230" => "æ",
167
+ "231" => "ç",
168
+ "232" => "è",
169
+ "233" => "é",
170
+ "234" => "ê",
171
+ "235" => "ë",
172
+ "236" => "ì",
173
+ "237" => "í",
174
+ "238" => "î",
175
+ "239" => "ï",
176
+ "240" => "ð",
177
+ "241" => "ñ",
178
+ "242" => "ò",
179
+ "243" => "ó",
180
+ "244" => "ô",
181
+ "245" => "õ",
182
+ "246" => "ö",
183
+ "247" => "÷",
184
+ "248" => "ø",
185
+ "249" => "ù",
186
+ "250" => "ú",
187
+ "251" => "û",
188
+ "252" => "ü",
189
+ "253" => "ý",
190
+ "254" => "þ",
191
+ "255" => "ÿ",
192
+ "338" => "Œ",
193
+ "339" => "œ",
194
+ "352" => "Š",
195
+ "353" => "š",
196
+ "376" => "Ÿ",
197
+ "402" => "ƒ",
198
+ "8211" => "–",
199
+ "8212" => "—",
200
+ "8216" => "‘",
201
+ "8217" => "’",
202
+ "8218" => "‚",
203
+ "8220" => "“",
204
+ "8221" => "”",
205
+ "8222" => "„",
206
+ "8224" => "†",
207
+ "8225" => "‡",
208
+ "8226" => "•",
209
+ "8230" => "…",
210
+ "8240" => "‰",
211
+ "8364" => "€",
212
+ "8482" => "™"
213
+ }
@@ -0,0 +1,3 @@
1
+ module HtmlNumberDecoder
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ require "html_number_decoder/mapping"
2
+
3
+ class HtmlNumberDecoder
4
+ PATTERN = /(&#(\d+);)/
5
+
6
+ def self.decode(string)
7
+ next_index = string.index(PATTERN)
8
+ return string if next_index.nil?
9
+
10
+ string[0..(next_index - 1)] +
11
+ convert($1) +
12
+ decode(string[(next_index + $1.length)..-1])
13
+ end
14
+
15
+ def self.convert(html_number)
16
+ number = html_number[/\d+/]
17
+ MAPPING[number]
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html_number_decoder
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eli Fatsi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - eli.fatsi@viget.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - README.md
22
+ - html_number_decoder.gemspec
23
+ - lib/html_number_decoder.rb
24
+ - lib/html_number_decoder/mapping.rb
25
+ - lib/html_number_decoder/version.rb
26
+ homepage: https://github.com/efatsi/html_number_decoder
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.5.1
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Decode HTML Numbers into characters
50
+ test_files: []