i18n_morse 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ..gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mikhail S. Pobolovets
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # i18n_morse
2
+
3
+ Ruby morse encoder/decoder with support for multiple languages.
4
+
5
+ ![Gem Version](https://badge.fury.io/rb/i18n_morse.png)
6
+ ![Build Status](https://secure.travis-ci.org/styx/i18n_morse.png?branch=master)
7
+ ![Dependency Status](https://gemnasium.com/styx/i18n_morse.png)
8
+ ![Code Climate](https://codeclimate.com/github/styx/i18n_morse.png)
9
+ ![Coverage Status](https://coveralls.io/repos/styx/i18n_morse/badge.png?branch=master)
10
+
11
+ This gem allows you transcode between Morse code and normal text in both ways.
12
+ The main difference from other gems it can be easily extended with new languages.
13
+ Currently it contains russian and english tables
14
+
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'i18n_morse'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install i18n_morse
29
+
30
+
31
+ ## Usage
32
+
33
+ TODO: Write usage instructions here
34
+
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
43
+
44
+
45
+ ## License
46
+
47
+ The MIT License (MIT)
48
+
49
+ Copyright (c) 2013 Mikhail S. Pobolovets
50
+
51
+ Permission is hereby granted, free of charge, to any person obtaining a copy
52
+ of this software and associated documentation files (the "Software"), to deal
53
+ in the Software without restriction, including without limitation the rights
54
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
55
+ copies of the Software, and to permit persons to whom the Software is
56
+ furnished to do so, subject to the following conditions:
57
+
58
+ The above copyright notice and this permission notice shall be included in
59
+ all copies or substantial portions of the Software.
60
+
61
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
64
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
67
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,126 @@
1
+ ---
2
+ en:
3
+ false:
4
+ A: .-
5
+ B: -...
6
+ C: -.-.
7
+ D: -..
8
+ E: .
9
+ F: ..-.
10
+ G: --.
11
+ H: ! '....'
12
+ I: ..
13
+ J: .---
14
+ K: -.-
15
+ L: .-..
16
+ M: --
17
+ N: -.
18
+ O: ! '---'
19
+ P: .--.
20
+ Q: --.-
21
+ R: .-.
22
+ S: ! '...'
23
+ T: ! '-'
24
+ U: ..-
25
+ V: ! '...-'
26
+ W: .--
27
+ X: -..-
28
+ Y: -.--
29
+ Z: --..
30
+ Ö: ! '---.'
31
+ Ñ: --.--
32
+ É: ..-..
33
+ Ü: ..--
34
+ Ä: .-.-
35
+ Š: ! '----'
36
+ '0': ! '-----'
37
+ '1': .----
38
+ '2': ..---
39
+ '3': ! '...--'
40
+ '4': ! '....-'
41
+ '5': ! '.....'
42
+ '6': -....
43
+ '7': --...
44
+ '8': ! '---..'
45
+ '9': ! '----.'
46
+ .: .-.-.-
47
+ ! ',': --..--
48
+ ! '!': -.-.--
49
+ (: -.--.
50
+ ): -.--.-
51
+ ! ':': ! '---...'
52
+ ;: -.-.-.
53
+ ! '''': .----.
54
+ ! '"': .-..-.
55
+ ! '-': -....-
56
+ /: -..-.
57
+ ! '?': ..--..
58
+ ? ! '
59
+
60
+ '
61
+ : -...-
62
+ ! '@': .--.-.
63
+ $: ! '...-..-'
64
+ _: ..--
65
+ true:
66
+ .-: A
67
+ -...: B
68
+ -.-.: C
69
+ -..: D
70
+ .: E
71
+ ..-.: F
72
+ --.: G
73
+ ! '....': H
74
+ ..: I
75
+ .---: J
76
+ -.-: K
77
+ .-..: L
78
+ --: M
79
+ -.: N
80
+ ! '---': O
81
+ .--.: P
82
+ --.-: Q
83
+ .-.: R
84
+ ! '...': S
85
+ ! '-': T
86
+ ..-: U
87
+ ! '...-': V
88
+ .--: W
89
+ -..-: X
90
+ -.--: Y
91
+ --..: Z
92
+ ! '---.': Ö
93
+ --.--: Ñ
94
+ ..-..: É
95
+ ..--: _
96
+ .-.-: Ä
97
+ ! '----': Š
98
+ ! '-----': '0'
99
+ .----: '1'
100
+ ..---: '2'
101
+ ! '...--': '3'
102
+ ! '....-': '4'
103
+ ! '.....': '5'
104
+ -....: '6'
105
+ --...: '7'
106
+ ! '---..': '8'
107
+ ! '----.': '9'
108
+ .-.-.-: .
109
+ --..--: ! ','
110
+ -.-.--: ! '!'
111
+ -.--.: (
112
+ -.--.-: )
113
+ ! '---...': ! ':'
114
+ -.-.-.: ;
115
+ .----.: ! ''''
116
+ .-..-.: ! '"'
117
+ -....-: ! '-'
118
+ -..-.: /
119
+ ..--..: ! '?'
120
+ -...-: ! '
121
+
122
+ '
123
+ .--.-.: ! '@'
124
+ ! '...-..-': $
125
+ ! '........': ''
126
+ ..-.-: ''
@@ -0,0 +1,126 @@
1
+ ---
2
+ ru:
3
+ false:
4
+ A: .-
5
+ Б: -...
6
+ В: .--
7
+ Г: --.
8
+ Д: -..
9
+ Е: .
10
+ Ж: ! '...-'
11
+ З: --..
12
+ И: ..
13
+ Й: .---
14
+ К: -.-
15
+ Л: .-..
16
+ М: --
17
+ Н: -.
18
+ О: ! '---'
19
+ П: .--.
20
+ Р: .-.
21
+ С: ! '...'
22
+ Т: ! '-'
23
+ У: ..-
24
+ Ф: ..-.
25
+ Х: ! '....'
26
+ Ц: -.-.
27
+ Ч: ! '---.'
28
+ Ш: ! '----'
29
+ Щ: --.-
30
+ Ъ: --.--
31
+ Ы: -.--
32
+ Ь: -..-
33
+ Э: ..-..
34
+ Ю: ..--
35
+ Я: .-.-
36
+ '0': ! '-----'
37
+ '1': .----
38
+ '2': ..---
39
+ '3': ! '...--'
40
+ '4': ! '....-'
41
+ '5': ! '.....'
42
+ '6': -....
43
+ '7': --...
44
+ '8': ! '---..'
45
+ '9': ! '----.'
46
+ .: .-.-.-
47
+ ! ',': --..--
48
+ ! '!': -.-.--
49
+ (: -.--.
50
+ ): -.--.-
51
+ ! ':': ! '---...'
52
+ ;: -.-.-.
53
+ ! '''': .----.
54
+ ! '"': .-..-.
55
+ ! '-': -....-
56
+ /: -..-.
57
+ ! '?': ..--..
58
+ ? ! '
59
+
60
+ '
61
+ : -...-
62
+ ! '@': .--.-.
63
+ $: ! '...-..-'
64
+ _: ..--
65
+ true:
66
+ .-: A
67
+ -...: Б
68
+ .--: В
69
+ --.: Г
70
+ -..: Д
71
+ .: Е
72
+ ! '...-': Ж
73
+ --..: З
74
+ ..: И
75
+ .---: Й
76
+ -.-: К
77
+ .-..: Л
78
+ --: М
79
+ -.: Н
80
+ ! '---': О
81
+ .--.: П
82
+ .-.: Р
83
+ ! '...': С
84
+ ! '-': Т
85
+ ..-: У
86
+ ..-.: Ф
87
+ ! '....': Х
88
+ -.-.: Ц
89
+ ! '---.': Ч
90
+ ! '----': Ш
91
+ --.-: Щ
92
+ --.--: Ъ
93
+ -.--: Ы
94
+ -..-: Ь
95
+ ..-..: Э
96
+ ..--: _
97
+ .-.-: Я
98
+ ! '-----': '0'
99
+ .----: '1'
100
+ ..---: '2'
101
+ ! '...--': '3'
102
+ ! '....-': '4'
103
+ ! '.....': '5'
104
+ -....: '6'
105
+ --...: '7'
106
+ ! '---..': '8'
107
+ ! '----.': '9'
108
+ .-.-.-: .
109
+ --..--: ! ','
110
+ -.-.--: ! '!'
111
+ -.--.: (
112
+ -.--.-: )
113
+ ! '---...': ! ':'
114
+ -.-.-.: ;
115
+ .----.: ! ''''
116
+ .-..-.: ! '"'
117
+ -....-: ! '-'
118
+ -..-.: /
119
+ ..--..: ! '?'
120
+ -...-: ! '
121
+
122
+ '
123
+ .--.-.: ! '@'
124
+ ! '...-..-': $
125
+ ! '........': ''
126
+ ..-.-: ''
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'morse/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'i18n_morse'
8
+ spec.version = Morse::VERSION
9
+ spec.authors = ['Mikhail S. Pobolovets']
10
+ spec.email = ['styx.mp@gmail.com']
11
+ spec.description = %q{Morse encoder/decoder for Ruby with language support}
12
+ spec.summary = %q{Morse encoder/decoder for Ruby with language support. Currently Russian and English are present.}
13
+ spec.homepage = "https://github.com/styx/i18n_morse"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'unicode'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'fuubar'
27
+ spec.add_development_dependency 'pry'
28
+ end
data/lib/ext/string.rb ADDED
@@ -0,0 +1,30 @@
1
+
2
+ # coding: UTF-8
3
+
4
+ require "unicode"
5
+
6
+ class String
7
+ def downcase
8
+ Unicode::downcase(self)
9
+ end
10
+
11
+ def downcase!
12
+ self.replace downcase
13
+ end
14
+
15
+ def upcase
16
+ Unicode::upcase(self)
17
+ end
18
+
19
+ def upcase!
20
+ self.replace upcase
21
+ end
22
+
23
+ def capitalize
24
+ Unicode::capitalize(self)
25
+ end
26
+
27
+ def capitalize!
28
+ self.replace capitalize
29
+ end
30
+ end
data/lib/morse.rb ADDED
@@ -0,0 +1,33 @@
1
+
2
+ require 'ext/string'
3
+ require 'morse/version'
4
+ require 'morse/codetables'
5
+
6
+ module Morse
7
+ include CodeTables
8
+
9
+ def to_morse(lang, skip_invalid = false)
10
+ transcode(lang, skip_invalid, false)
11
+ end
12
+
13
+ def from_morse(lang, skip_invalid = false)
14
+ transcode(lang, skip_invalid, true)
15
+ end
16
+
17
+ private
18
+
19
+ def to_char_array(encoded)
20
+ string = self.upcase
21
+ encoded ? string.split : string.split('')
22
+ end
23
+
24
+ def transcode(lang, skip_invalid, encoded)
25
+ arr = to_char_array(encoded).map do |c|
26
+ CODE_TABLES[lang][encoded][c] || (c unless skip_invalid)
27
+ end
28
+
29
+ encoded ? arr.join : arr.join(' ')
30
+ end
31
+
32
+ String.send(:include, Morse)
33
+ end
@@ -0,0 +1,10 @@
1
+ # coding: utf-8
2
+
3
+ require 'yaml'
4
+
5
+ module CodeTables
6
+ gem_root = Gem.loaded_specs['i18n_morse'].full_gem_path
7
+
8
+ CODE_TABLES = {}
9
+ Dir["#{gem_root}/codetables/*.yml"].each {|f| CODE_TABLES.merge!(YAML.load(File.read(f))) }
10
+ end
@@ -0,0 +1,3 @@
1
+ module Morse
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,40 @@
1
+ # coding: UTF-8
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ describe 'Morse' do
6
+ describe '#to_morse' do
7
+ context 'valid chars' do
8
+ it 'encodes EN string' do
9
+ 'Morse'.to_morse('en').should eq '-- --- .-. ... .'
10
+ end
11
+
12
+ it 'encodes RU string' do
13
+ 'Морзе'.to_morse('ru').should eq '-- --- .-. --.. .'
14
+ end
15
+ end
16
+
17
+ context 'with bad chars' do
18
+ it 'preserves bad chars if set to preserve' do
19
+ 'M&%#e'.to_morse('en').should eq '-- & % # .'
20
+ end
21
+
22
+ it 'removes bad chars if not set to preserve' do
23
+ 'M&%#e'.to_morse('en', true).should eq '-- .'
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '#from_morse' do
29
+ it 'decodes EN string' do
30
+ '-- --- .-. ... .'.from_morse('en').should eq 'MORSE'
31
+ end
32
+
33
+ it 'decodes RU string' do
34
+ '-- --- .-. --.. .'.from_morse('ru').should eq 'МОРЗЕ'
35
+ end
36
+ end
37
+
38
+
39
+
40
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rspec'
5
+ require 'morse'
6
+ require 'pry'
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ #Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+
12
+ #RSpec.configure do |config|
13
+ #end
File without changes
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n_morse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mikhail S. Pobolovets
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: unicode
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
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: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
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
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: fuubar
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Morse encoder/decoder for Ruby with language support
111
+ email:
112
+ - styx.mp@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - LICENSE.txt
120
+ - README.md
121
+ - Rakefile
122
+ - codetables/codetable.en.yml
123
+ - codetables/codetable.ru.yml
124
+ - i18n_morse.gemspec
125
+ - lib/ext/string.rb
126
+ - lib/morse.rb
127
+ - lib/morse/codetables.rb
128
+ - lib/morse/version.rb
129
+ - spec/morse_spec.rb
130
+ - spec/spec_helper.rb
131
+ - spec/support/.gitkeep
132
+ homepage: https://github.com/styx/i18n_morse
133
+ licenses:
134
+ - MIT
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ segments:
146
+ - 0
147
+ hash: 1700120680220015236
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ segments:
155
+ - 0
156
+ hash: 1700120680220015236
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 1.8.25
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: Morse encoder/decoder for Ruby with language support. Currently Russian and
163
+ English are present.
164
+ test_files:
165
+ - spec/morse_spec.rb
166
+ - spec/spec_helper.rb
167
+ - spec/support/.gitkeep