Simple Morse Code Encode and Decode Tool
Add this line to your application's Gemfile:
gem 'morse-code-rb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install morse-code-rb
require 'morse_code'
content = 'I am Robot.'
MorseCode::Encoder.new(content).encode
=> ".. / .- -- / .-. --- -... --- - .-.-.-"
MorseCode::Encoder.new(content).dit_dah
=> "DITDIT / DITDAH DAHDAH / DITDAHDIT DAHDAHDAH DAHDITDITDIT DAHDAHDAH DAH DITDAHDITDAHDITDAH"
content = 'I am Chinese 我是中国人'
MorseCode::Encoder.new(content).encode
=> ".. / .- -- / -.-. .... .. -. . ... . / --...-....-...- --..--...-.---- -..---...-.--.- -.-.--.------.- -..---.-.---.-."
MorseCode::Encoder.new(content).dit_dah
=> "DITDIT / DITDAH DAHDAH / DAHDITDAHDIT DITDITDITDIT DITDIT DAHDIT DIT DITDITDIT DIT / DAHDAHDITDITDITDAHDITDITDITDITDAHDITDITDITDAH DAHDAHDITDITDAHDAHDITDITDITDAHDITDAHDAHDAHDAH DAHDITDITDAHDAHDAHDITDITDITDAHDITDAHDAHDITDAH DAHDITDAHDITDAHDAHDITDAHDAHDAHDAHDAHDAHDITDAH DAHDITDITDAHDAHDAHDITDAHDITDAHDAHDAHDITDAHDIT"
require 'morse_code'
content = 'I am Robot.'
MorseCode::Encoder.new(content).wave
=> "/tmp/morse_code-5b9b3aa176.wav"
you can open wavefile and listen to the morse code sound.
require 'morse_code'
content = '.. / .- -- / .-. --- -... --- - .-.-.-'
MorseCode::Decoder.new(content).decode
=> "I AM ROBOT."
dit_dah = 'DITDIT / DITDAH DAHDAH / DITDAHDIT DAHDAHDAH DAHDITDITDIT DAHDAHDAH DAH DITDAHDITDAHDITDAH'
MorseCode::Decoder.new(dit_dah).dit_dah_to
=> "I AM ROBOT."
content = '.. / .- -- / -.-. .... .. -. . ... . / --...-....-...- --..--...-.---- -..---...-.--.- -.-.--.------.- -..---.-.---.-.'
MorseCode::Decoder.new(content).decode
=> "I AM CHINESE 我是中国人"
$> mc
mc commands:
mc decode MESSAGE # decode Morse Code as original message
mc encode MESSAGE # encode message as Morse Code
mc help [COMMAND] # Describe available commands or one specific command
$> mc help encode
Usage:
mc encode MESSAGE
Options:
-d, [--dit-dah], [--no-dit-dah] # encode DITDAH message
-w, [--wave], [--no-wave] # gen morse code wav
encode message as Morse Code
$> mc -e 'I am Robot.'
=> ".. / .- -- / .-. --- -... --- - .-.-.-"
$> mc -e 'I am Robot.' --dit-dah
=> "DITDIT / DITDAH DAHDAH / DITDAHDIT DAHDAHDAH DAHDITDITDIT DAHDAHDAH DAH DITDAHDITDAHDITDAH"
$> mc -e 'I am Chinese 我是中国人'
=> ".. / .- -- / -.-. .... .. -. . ... . / --...-....-...- --..--...-.---- -..---...-.--.- -.-.--.------.- -..---.-.---.-."
$> mc -e -w 'I am Chinese 我是中国人'
=> ".. / .- -- / -.-. .... .. -. . ... . / --...-....-...- --..--...-.---- -..---...-.--.- -.-.--.------.- -..---.-.---.-."
=> "Generate wave file: /tmp/morse_code-0d56cd233e.wav"
you can open wavefile and listen to the morse code sound.
$> mc -d '.. / .- -- / .-. --- -... --- - .-.-.-'
=> "I AM ROBOT."
$> mc -d 'DITDIT / DITDAH DAHDAH / DITDAHDIT DAHDAHDAH DAHDITDITDIT DAHDAHDAH DAH DITDAHDITDAHDITDAH' --dit-dah
=> "I AM ROBOT."
$> mc -d '.. / .- -- / -.-. .... .. -. . ... . / --...-....-...- --..--...-.---- -..---...-.--.- -.-.--.------.- -..---.-.---.-.'
=> "I AM CHINESE 我是中国人"
$ git https://github.com/superiorlu/morse_code.git
$ cd morse_code
$ git remote add upstream https://github.com/superiorlu/morse_code.git
$ git checkout master
$ git pull upstream master
$ git checkout -b my-feature-branch
$ bundle exec rake test
Click the 'Pull Request'
button and fill out the form.
MIT License. See LICENSE for details.