Code Monkey home page Code Monkey logo

telegraph's Introduction

Telegraph

Telegraph is a Ruby gem that provides straightforward text-to-morse and morse-to-text translators

It uses as reference the document 'RECOMMENDATION ITU-R M.1677' from the International Telecommunication Union, Radiocommunication Sector (ITU-R), the United Nations agency for information and communication technology issues.

Build Status Gem Version

Getting started

Install the gem:

$ gem install telegraph

Then depending on your project you may:

require the gem (if a ruby project):

    require 'telegraph'

or add it to your Gemfile:

    gem 'telegraph', :git => 'git://github.com/xuanxu/telegraph.git'

Usage

The simplest way to read or write morse code is using directly the two methods defined in Telegraph:

# Converts text to morse characters:
Telegraph.text_to_morse("Hello world")  #=> ".... . .-.. .-.. ---       .-- --- .-. .-.. -.."

# Reads morse characters into text:
Telegraph.morse_to_text(".... . .-.. .-.. ---       .-- --- .-. .-.. -..")  #=> hello world"

In the Telegraph module you will find defined also the most commonly used prosigns:

# Error sign:
Telegraph::Error    #=> "........"

#The complete list of prosigns:
Telegraph::Error
Telegraph::Understood
Telegraph::Invitation_to_transmit
Telegraph::Wait
Telegraph::End_of_work
Telegraph::Starting_signal

All the generated morse code will use the character '.' as short signal (aka dot) and the character '-' as long signal (aka dash).

If you need to write or read using different characters as short and long signals you can do it instantiating your own Telegraph::MorseTransmission class:

# User defined dot & dash (:short and :long defaults to '.' and '-')
morser = Telegraph::MorseTransmission.new(:short =>'x', :long => '3')

and then using the methods to read/write:

# write morse code with custom signals
morser.text_to_morse("Hello world")  #=> "xxxx x x3xx x3xx 333       x33 333 x3x x3xx 3xx"

# read morse code with custom signals
morser.morse_to_text("xxxx x x3xx x3xx 333       x33 333 x3x x3xx 3xx")  #=> hello world"
morser.error    #=> "xxxxxxxx"

== Credits

Author:: Juanjo Bazán Copyright:: Copyright (c) 2013 - ∞ Juanjo Bazán License:: Released under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.