Skip to content

superiorlu/morse_code

Repository files navigation

MorseCode

Simple Morse Code Encode and Decode Tool

Gem Version Build Status Maintainability Test Coverage GitHub license

Installation

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

Usage

Encode

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"

Generate Wave File

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.

Decode

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 我是中国人"

Terminal

$> 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

encode

$> 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.

decode

$> 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 我是中国人"

Contributing

Fork the Project

$ git https://github.com/superiorlu/morse_code.git
$ cd morse_code
$ git remote add upstream https://github.com/superiorlu/morse_code.git

Create a Toptic Branch

$ git checkout master
$ git pull upstream master
$ git checkout -b my-feature-branch

Run Test

$ bundle exec rake test

Make a Pull Request

Click the 'Pull Request' button and fill out the form.

Resource

License

MIT License. See LICENSE for details.

About

Simple Morse Code Encode and Decode Tool

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published