postycode 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/postycode +25 -0
- data/lib/postycode.rb +27 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 96ea3645c619ba5116538f0582b8897246d67f99
|
4
|
+
data.tar.gz: 4d8bf1e265da6c7de4f2e0eb715ae223a57d1a2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06087f802ac017f114a6744b05e53bc593c035a0bb7639e1608afadbcf9b2fedfe08070b7bbc3118f4c7e88d583611a04bcba0f83c9e7f041c45c35df501423e
|
7
|
+
data.tar.gz: fe66b66631fbeea6b3c9f4a9e89a6d8ad2f4914187346990430dc783b34ce4fa5e7c539723d8f725f82fe512180b9ce7a2d4520fe1e5c8af18cf6aaeb622de24
|
data/bin/postycode
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'postycode'
|
4
|
+
|
5
|
+
invalid_usage = "Invalid usage. Use --help or -h option for additional information."
|
6
|
+
help = "Usage: postycode [-h] utf8code[-utf8code] [utf8code[-utf8code]] ...
|
7
|
+
|
8
|
+
Examples:
|
9
|
+
postycode 0050-0059
|
10
|
+
postycode 00A3-00B9 0003-0042
|
11
|
+
postycode 0352 0B23-0B59 0936 12AA
|
12
|
+
"
|
13
|
+
|
14
|
+
# Make sure command was run properly
|
15
|
+
if ARGV.count > 0
|
16
|
+
abort(help) if (ARGV[0] == "--help") || (ARGV[0] == "-h")
|
17
|
+
|
18
|
+
ARGV.each do |arg|
|
19
|
+
abort(invalid_usage) unless (arg =~ /^[0-9A-Fa-f]{4}(-[0-9A-Fa-f]{4})?$/)
|
20
|
+
end
|
21
|
+
else
|
22
|
+
abort(help)
|
23
|
+
end
|
24
|
+
|
25
|
+
puts Postycode.parse ARGV
|
data/lib/postycode.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# The main Postycode driver
|
2
|
+
class Postycode
|
3
|
+
# Convert hexadecimal Unicode code point ranges into escaped Unicode
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
# >> Postycode.parse(["00AB-00AD", "0041"])
|
7
|
+
# => "\u00ab\u00ac\u00ad\0041"
|
8
|
+
#
|
9
|
+
# Arguments:
|
10
|
+
# argv: (Array)
|
11
|
+
|
12
|
+
# Converts code point ranges in ARGV to final string
|
13
|
+
def self.parse(argv)
|
14
|
+
escaped_syms = String.new
|
15
|
+
|
16
|
+
argv.each do |arg|
|
17
|
+
range = arg.scan(/[0-9A-Fa-f]{4}/)
|
18
|
+
if range.count == 2 # If given a range instead of an individual code point
|
19
|
+
range = (range[0].hex..range[1].hex).to_a # 00AB-00AD -> [171, 172, 173]
|
20
|
+
range.collect! { |num| num.to_s(16).rjust(4, '0') } # e.g., 172 -> 00ac
|
21
|
+
end
|
22
|
+
range.collect! { |num| num.prepend('\u') } # e.g., 00ac -> \u00ac
|
23
|
+
escaped_syms << range.join
|
24
|
+
end
|
25
|
+
escaped_syms
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: postycode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ersin Akinci
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
Postycode builds strings of escaped Unicode symbols when you give it hexadecimal
|
15
|
+
code point ranges.
|
16
|
+
email: ersin.akinci@gmail.com
|
17
|
+
executables:
|
18
|
+
- postycode
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- bin/postycode
|
23
|
+
- lib/postycode.rb
|
24
|
+
homepage: https://github.com/earksiinni/postycode
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.0.3
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Easily generate strings of escaped Unicode
|
48
|
+
test_files: []
|