ascii 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -6
- data/lib/ascii.rb +7 -0
- data/lib/ascii/codepoint.rb +11 -5
- data/lib/ascii/unidecoder.rb +7 -0
- data/lib/ascii/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2aea619f9906a262e98683d34465cf75ece8b157
|
4
|
+
data.tar.gz: 69005d73fba88557d4a779370a3cd2f02f48bcc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86eaab94b5547624220da024e477820d1e4dee093fc5e32d3c9fc48bc02b8585f45a58a9f6b199845a96a3169ddaf39c8ad53e5934fc3f4c875fe5f3a7c73e73
|
7
|
+
data.tar.gz: dc8a3e2e76eac549bfdf11424ef3389b26de3bd972e3f0511ffe5e35a20964c69ab6eb5c8ed1ed466394931049872748b408408cb29b40cac15333ff27af3f9b
|
data/README.md
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
# Ascii
|
2
|
-
[![Gem Version](https://img.shields.io/gem/v/ascii.svg)]
|
3
|
-
[![Build Status](https://img.shields.io/travis/rwz/ascii.svg)]
|
4
|
-
[![Code Climate](https://img.shields.io/codeclimate/github/rwz/ascii.svg)]
|
5
|
-
[gem]: https://rubygems.org/gems/ascii
|
6
|
-
[travis]: http://travis-ci.org/rwz/ascii
|
7
|
-
[codeclimate]: https://codeclimate.com/github/rwz/ascii
|
2
|
+
[![Gem Version](https://img.shields.io/gem/v/ascii.svg)](https://rubygems.org/gems/ascii)
|
3
|
+
[![Build Status](https://img.shields.io/travis/rwz/ascii.svg)](http://travis-ci.org/rwz/ascii)
|
4
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/rwz/ascii.svg)](https://codeclimate.com/github/rwz/ascii)
|
8
5
|
|
9
6
|
This library provides method to transliterate Unicode characters to an ASCII
|
10
7
|
approximation.
|
data/lib/ascii.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
require "ascii/unidecoder"
|
2
2
|
require "ascii/version"
|
3
3
|
|
4
|
+
# The main module of the gem, exposes only <tt>process</tt> method.
|
5
|
+
# Can be mixed into other classes.
|
4
6
|
module Ascii
|
5
7
|
extend self
|
6
8
|
|
9
|
+
# Generates the approximate ASCII repsentation of the given
|
10
|
+
# string
|
11
|
+
#
|
12
|
+
# @param str [String] The string you want to approximate
|
13
|
+
# @return [String] The ASCII approximation of the input string
|
7
14
|
def process(str)
|
8
15
|
Unidecoder.new(str).to_ascii
|
9
16
|
end
|
data/lib/ascii/codepoint.rb
CHANGED
@@ -1,24 +1,30 @@
|
|
1
1
|
require "yaml"
|
2
2
|
|
3
3
|
module Ascii
|
4
|
+
|
5
|
+
# The class responsible for translating a Unicode char to its ASCII
|
6
|
+
# representation
|
4
7
|
class Codepoint
|
8
|
+
# @return [Integer] the code of the unicode character
|
5
9
|
attr_reader :code
|
6
10
|
|
7
|
-
|
8
|
-
filename = File.expand_path("../../../data/#{group_name}.yml", __FILE__)
|
9
|
-
hash[name] = YAML.load_file(filename)
|
10
|
-
end
|
11
|
-
|
11
|
+
# @param char [String] the unicode char
|
12
12
|
def initialize(char)
|
13
13
|
@code = char.unpack("U").first
|
14
14
|
end
|
15
15
|
|
16
|
+
# @return [String] an ASCII representation of input
|
16
17
|
def decode
|
17
18
|
group.at(group_index)
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
21
22
|
|
23
|
+
GROUPS = Hash.new do |hash, group_name|
|
24
|
+
filename = File.expand_path("../../../data/#{group_name}.yml", __FILE__)
|
25
|
+
hash[name] = YAML.load_file(filename)
|
26
|
+
end
|
27
|
+
|
22
28
|
def group
|
23
29
|
GROUPS[group_name]
|
24
30
|
end
|
data/lib/ascii/unidecoder.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
require "ascii/codepoint"
|
2
2
|
|
3
3
|
module Ascii
|
4
|
+
|
5
|
+
# The class resposible for generating ASCII representation of the
|
6
|
+
# given string
|
4
7
|
class Unidecoder
|
5
8
|
attr_reader :input
|
6
9
|
|
10
|
+
# @param input [String] string to process
|
7
11
|
def initialize(input)
|
8
12
|
@input = input.to_s
|
9
13
|
end
|
10
14
|
|
15
|
+
# Processes input string and returns ASCII
|
16
|
+
#
|
17
|
+
# @return [String] An ASCII approximation of input string
|
11
18
|
def to_ascii
|
12
19
|
input.gsub(/[^\x00-\x7f]/u, &method(:decode)).strip
|
13
20
|
end
|
data/lib/ascii/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ascii
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pravosud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This library provides methods to transliterate Unicode characters to
|
14
14
|
an ASCII approximation
|
@@ -238,3 +238,4 @@ summary: Create an ASCII representation of localized string
|
|
238
238
|
test_files:
|
239
239
|
- spec/ascii_spec.rb
|
240
240
|
- spec/spec_helper.rb
|
241
|
+
has_rdoc:
|