morse_fun 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/morse_fun.rb +138 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0e008cc41493cac8bd11b6f0799d5e6c395a383b
4
+ data.tar.gz: 939e5badf72eedf5de54ae8e694a57daba27ed3d
5
+ SHA512:
6
+ metadata.gz: 72745f2b75fea3bcfa6afc924382746eaf0276565ca959c35c21e7470248c1718f81f8abc6bdd27f89520237aec76a9063d157bcc18a0f3d9db670dd4425460f
7
+ data.tar.gz: d6d0045a5f971b14e2f6d8cadb5cd3e4d821cfeff79e2f63f4c8af234c68f33726ba429698f6ff66adfcc8bdd32223aa70ed0303f9971f1437a10758ac9e7d4d
data/lib/morse_fun.rb ADDED
@@ -0,0 +1,138 @@
1
+ # morse_tms.rb
2
+ #
3
+ # Copyright (C) September 7, 2014
4
+ #
5
+ # Author: Abbas Taghiloei AKA MR.0x41 <sir.0x41@gmail.com>
6
+ #
7
+ # == License
8
+ #
9
+ # The MIT License (MIT)
10
+ #
11
+ # Copyright (c) [2014] [morse_tms v 0.1 Ruby Gem]
12
+ #
13
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ # of this software and associated documentation files (the "Software"), to deal
15
+ # in the Software without restriction, including without limitation the rights
16
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ # copies of the Software, and to permit persons to whom the Software is
18
+ # furnished to do so, subject to the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be included in all
21
+ # copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ # SOFTWARE.
30
+ #
31
+
32
+ raise "Please, use ruby 2.0.0 or later." if RUBY_VERSION < "2.0.0"
33
+
34
+ require "Win32API"
35
+
36
+ Beep = Win32API.new("kernel32", "Beep", ["I", "I"], 'v')
37
+ def morsound freq, duration
38
+ Beep.call(freq, duration)
39
+ end
40
+
41
+ def morsehash
42
+ mohash = Hash.new
43
+ mohash = { '"' => '---...',
44
+ ',' => '--..--',
45
+ '?' => '..--..',
46
+ '@' => '.--.-.',
47
+ '-' => '-....-',
48
+ '0' => '-----',
49
+ '5' => '.....',
50
+ '1' => '.----',
51
+ '2' => '..---',
52
+ '3' => '...--',
53
+ '4' => '....-',
54
+ '6' => '-....',
55
+ '7' => '--...',
56
+ '8' => '---..',
57
+ '9' => '----.',
58
+ '/' => '-..-.',
59
+ '=' => '-...-',
60
+ 'B' => '-...',
61
+ 'C' => '-.-.',
62
+ 'F' => '..-.',
63
+ 'J' => '.---',
64
+ 'L' => '.-..',
65
+ 'P' => '.--.',
66
+ 'Q' => '--.-',
67
+ 'V' => '...-',
68
+ 'X' => '-..-',
69
+ 'Y' => '-.--',
70
+ 'Z' => '--..',
71
+ 'H' => '....',
72
+ 'D' => '-..',
73
+ 'G' => '--.',
74
+ 'K' => '-.-',
75
+ 'R' => '.-.',
76
+ 'U' => '..-',
77
+ 'W' => '.--',
78
+ 'S' => '...',
79
+ 'O' => '---',
80
+ 'M' => '--',
81
+ 'I' => '..',
82
+ 'A' => '.-',
83
+ 'N' => '-.',
84
+ 'T' => '-',
85
+ 'E' => '.',
86
+ }
87
+ @morsevalue, @morsekeys = Array.new
88
+ @morsevalue = mohash.values
89
+ @morsekeys = mohash.keys
90
+ end
91
+
92
+ def string_to_morse(str)
93
+ if str == nil
94
+ return 0
95
+ else
96
+ str = str.upcase
97
+ str.gsub!(" ", " ")
98
+ i = 0
99
+ while i < @morsevalue.size
100
+ str.gsub!("#{@morsekeys[i]}", "#{@morsevalue[i]} ")
101
+ i = i + 1
102
+ end
103
+ end
104
+ return str
105
+ end
106
+
107
+ def morse_to_string(mrs)
108
+ if mrs == nil
109
+ return 0
110
+ else
111
+ i = 0
112
+ while i < @morsevalue.size
113
+ mrs.gsub!("#{@morsevalue[i]}", "#{@morsekeys[i]}")
114
+ i = i + 1
115
+ end
116
+ end
117
+ return mrs
118
+ end
119
+
120
+ def morse_to_voice(mrs)
121
+ if mrs == nil
122
+ return 0
123
+ else
124
+ i = 0
125
+ while i < mrs.size
126
+ if mrs[i] == '.'
127
+ morsound 1000, 200
128
+ elsif mrs[i] == '-'
129
+ morsound 1000, 600
130
+ elsif mrs[i] == ' '
131
+ sleep 0.25
132
+ end
133
+ i = i + 1
134
+ end
135
+ end
136
+ end
137
+
138
+ morsehash()
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: morse_fun
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - A-Taghiloei
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Gem to have fun with morse code. convert string to morse or vice versa,
14
+ and create the morce voice (Beep !!!) [ Uses Win32API ].
15
+ email: sir.0x41@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/morse_fun.rb
21
+ homepage: http://www.opensec.ir
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: A Gem to handle Morse codes the simple way.
45
+ test_files: []