diacritize 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in diacritize.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 C4mz0r
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ # Diacritize
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'diacritize'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install diacritize
18
+
19
+ ## Usage
20
+
21
+ This gem allows us to take a string in English and then applies diacritical marks to the characters (when a suitable diacritical character is available).
22
+
23
+ How can this be useful? Perhaps you have some boring test data, and you'd like to shake things up a bit while at the same time keeping the strings "human readable". Or maybe you have an application that seems to be working with standard characters, and you want to throw some of these different characters at it to see if it can handle them. Perhaps you just want to annoy your friends by diacritizing your email before you send it to them.
24
+
25
+
26
+ ```ruby
27
+ # Here are some examples!
28
+ require 'diacritize'
29
+
30
+ # The normal call gives the same result when called multiple times with the same input:
31
+ Diacritize::diacritize("It looks like we going to have a SUNNY DAY!")
32
+ # => "Ìt lòòks lìkè wè gòìñg tò hàvè à SÙÑÑÝ ÐÀÝ!"
33
+
34
+ # If there are no possible diacritical substitutes, then the output does not differ from the input:
35
+ Diacritize::diacritize("qwrtz")
36
+ # => "qwrtz"
37
+
38
+ # The random call will differ when called multiple times (it randomly chooses a substitute when many are available for a given character):
39
+ Diacritize::random_diacritize("It looks like we going to have a SUNNY DAY!")
40
+ # => "Ìt lôöks lîkë wë gøîñg tõ hàvé å SÜÑÑÝ ÐÅÝ!"
41
+ # => "Ît lõøks lîkê wé göîñg tó hávè à SÚÑÑÝ ÐÅÝ!"
42
+ # => etc...
43
+
44
+ ```
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/C4mz0r/diacritize.
55
+
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
60
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "diacritize"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'diacritize/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "diacritize"
8
+ spec.version = Diacritize::VERSION
9
+ spec.authors = ["C4mz0r"]
10
+ spec.email = ["aut0x@hotmail.com"]
11
+
12
+ spec.summary = %q{Diacritizes a string, replacing English alphabetical characters with diacritical ones}
13
+ spec.description = %q{Replace characters in an existing string with similar-looking diacritical ones (e.g. vowels with dots over them, characters with accents on them, etc.). This allows you to create strings that have different characters in them, but still keep the string human readable. }
14
+ spec.homepage = "https://github.com/C4mz0r/diacritize"
15
+ spec.license = "MIT"
16
+
17
+ =begin
18
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
19
+ # delete this section to allow pushing this gem to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
24
+ end
25
+ =end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.10"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec"
35
+ end
@@ -0,0 +1,48 @@
1
+ require "diacritize/version"
2
+
3
+ module Diacritize
4
+
5
+ DIACRITS = { 'a' => ("\u00E0".."\u00E5").to_a,
6
+ 'c' => ["\u00E7"],
7
+ 'e' => ("\u00E8".."\u00EB").to_a,
8
+ 'i' => ("\u00EC".."\u00EF").to_a,
9
+ 'n' => ["\u00F1"],
10
+ 'o' => ("\u00F2".."\u00F6").to_a + ["\u00F8"],
11
+ 'u' => ("\u00F9".."\u00FC").to_a,
12
+ 'y' => ["\u00FD", "\u00FF"],
13
+ 'A' => ("\u00C0".."\u00C5").to_a,
14
+ 'C' => ("\u00C8".."\u00CB").to_a,
15
+ 'D' => ["\u00D0"],
16
+ 'E' => ("\u00C8".."\u00CB").to_a,
17
+ 'I' => ("\u00CC".."\u00CF").to_a,
18
+ 'N' => ["\u00D1"],
19
+ 'O' => ("\u00D2".."\u00D6").to_a + ["\u00D8"],
20
+ 'U' => ("\u00D9".."\u00DC").to_a,
21
+ 'Y' => ["\u00DD"]
22
+ }
23
+
24
+ module_function
25
+
26
+ # Replace English alphabet characters with
27
+ # others that have diacritical marks. Deterministic,
28
+ # chooses the first available diacritical character from
29
+ # each possible option.
30
+ def diacritize(s)
31
+ s.split("").each_with_index do |c,i|
32
+ s[i] = DIACRITS[c].first if !DIACRITS[c].nil?
33
+ end
34
+ s
35
+ end
36
+
37
+ # Replace English alphabet characters with
38
+ # others that have diacritical marks. Randomly
39
+ # chooses a diacritical character from
40
+ # each possible option.
41
+ def random_diacritize(s)
42
+ s.split("").each_with_index do |c,i|
43
+ s[i] = DIACRITS[c].sample if !DIACRITS[c].nil?
44
+ end
45
+ s
46
+ end
47
+
48
+ end
@@ -0,0 +1,3 @@
1
+ module Diacritize
2
+ VERSION = "0.1.0.pre"
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diacritize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - C4mz0r
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-10-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.10'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! 'Replace characters in an existing string with similar-looking diacritical
63
+ ones (e.g. vowels with dots over them, characters with accents on them, etc.). This
64
+ allows you to create strings that have different characters in them, but still keep
65
+ the string human readable. '
66
+ email:
67
+ - aut0x@hotmail.com
68
+ executables: []
69
+ extensions: []
70
+ extra_rdoc_files: []
71
+ files:
72
+ - .gitignore
73
+ - .rspec
74
+ - .travis.yml
75
+ - Gemfile
76
+ - LICENSE.txt
77
+ - README.md
78
+ - Rakefile
79
+ - bin/console
80
+ - bin/setup
81
+ - diacritize.gemspec
82
+ - lib/diacritize.rb
83
+ - lib/diacritize/version.rb
84
+ homepage: https://github.com/C4mz0r/diacritize
85
+ licenses:
86
+ - MIT
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>'
101
+ - !ruby/object:Gem::Version
102
+ version: 1.3.1
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.23
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Diacritizes a string, replacing English alphabetical characters with diacritical
109
+ ones
110
+ test_files: []