Skip to content

Commit

Permalink
Merge pull request #3 from MussieTeka/final-touch
Browse files Browse the repository at this point in the history
Final touch
  • Loading branch information
MussieTeka committed Jun 15, 2023
2 parents 9116d11 + f1b3ce6 commit 3bd71a7
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 41 deletions.
174 changes: 172 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,172 @@
# morse-code-decoder
Ruby implementation of Morse code decoding methods with reusable functions for decoding characters, words, and messages.
<a name="readme-top"></a>

<div align="center">
<h3><b>Morse Code Decoder</b></h3>
</div>

# 📗 Table of Contents

- [📖 About the Project](#about-project)
- [🛠 Built With](#built-with)
- [Tech Stack](#tech-stack)
- [Key Features](#key-features)
- [💻 Getting Started](#getting-started)
- [Setup](#setup)
- [Prerequisites](#prerequisites)
- [Install](#install)
- [Usage](#usage)
- [Run tests](#run-tests)
- [Deployment](#triangular_flag_on_post-deployment)
- [👥 Authors](#authors)
- [🔭 Future Features](#future-features)
- [🤝 Contributing](#contributing)
- [⭐️ Show your support](#support)
- [🙏 Acknowledgements](#acknowledgements)
- [❓ FAQ (OPTIONAL)](#faq)
- [📝 License](#license)

# 📖 Morse Code Decoder <a name="about-project"></a>
This project is a Morse code decoder implemented in Ruby. It provides methods to decode Morse code characters, words, and entire messages. The decoded message can be printed or used in other applications.

## 🛠 Built With <a name="built-with"></a>

### Tech Stack <a name="tech-stack"></a>

The project is built with the following technologies:

- Ruby

<p align="right">(<a href="#readme-top">back to top</a>)</p>

### Key Features <a name="key-features"></a>

The key features of this project include:

- Decoding Morse code characters
- Decoding Morse code words
- Decoding entire messages in Morse code

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 💻 Getting Started <a name="getting-started"></a>

To get started with the project, follow the instructions below.


### Setup

To set up the project locally, you need to have Ruby installed on your system.

### Prerequisites

- Ruby (version 2.5 or above)

### Install

1. Clone the repository:

```sh
clone git@github.com:MussieTeka/morse-code-decoder.git
```
2. Change into the project directory:

```
cd morse-code-decoder
```
### Usage

To use the Morse code decoder, follow these steps:

1. Open the morse_decoder.rb file in a text editor.
2. Modify the message variable to contain the Morse code you want to decode.
3. Run the script using the command:

```
ruby morse_decoder.rb
```
4. The decoded message will be printed on the console.
### Run tests

There are no tests available for this project.
### Deployment

There is no specific deployment process for this project as it is a code implementation. However, you can integrate the Morse code decoder into your own Ruby applications.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 👥 Author <a name="authors"></a>

This project was developed by:

👤 **Umair Hamza**

- GitHub: [@emhamza](https://github.com/emhamza)
- Twitter: [@uhamzaz](https://twitter.com/uhamzaz)
- LinkedIn: [Umair Hamza](https://www.linkedin.com/in/umair-hamza-a8262b261/)

👤 **Mussie Kahsay**

- GitHub: [@MussieTeka](https://github.com/MussieTeka)
- Twitter: [@mussieteka](https://twitter.com/mussieteka)
- LinkedIn: [@mussieteka](https://linkedin.com/in/mussieteka)

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 🔭 Future Features <a name="future-features"></a>

Possible future features for this project include:

- Encoding text into Morse code
- Providing a command-line interface (CLI) for interactive decoding

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 🤝 Contributing <a name="contributing"></a>

Contributions, issues, and feature requests are welcome!

Feel free to check the [issues page](../../issues/).

If you would like to contribute to this project, you can follow these steps:

1. Fork the repository.
2. Create a new branch for your changes.
3. Make your changes and commit them.
4. Push your changes to your forked repository.
5. Create a pull request back to the original repository.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## ⭐️ Show your support <a name="support"></a>

If you like this project, please give it a star on GitHub.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 🙏 Acknowledgments <a name="acknowledgements"></a>

- [Ruby](https://www.ruby-lang.org/en/)
- [GitHub](https://github.com/)
- [Microverse](https://www.microverse.org/)

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## ❓ FAQ (OPTIONAL) <a name="faq"></a>

- **Can I modify and redistribute this project?**

- Yes, you can modify and redistribute this project as long as you follow the terms of the MIT license.

- **How can I contribute to this project?**

- Contributions, issues, and feature requests are welcome! You can check the issues page to see if there are any current issues or feature requests that you can work on. If not, feel free to submit a new issue or pull request. Before contributing, please read the CONTRIBUTING.md file for guidelines on how to contribute to this project.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- LICENSE -->

## 📝 License <a name="license"></a>

This project is [MIT](./LICENSE) licensed.

<p align="right">(<a href="#readme-top">back to top</a>)</p>
69 changes: 30 additions & 39 deletions morse_decoder.rb
Original file line number Diff line number Diff line change
@@ -1,50 +1,41 @@
MORSE_CODE_DICT = {
'.-' => 'A',
'-...' => 'B',
'-.-.' => 'C',
'-..' => 'D',
'.' => 'E',
'..-.' => 'F',
'--.' => 'G',
'....' => 'H',
'..' => 'I',
'.---' => 'J',
'-.-' => 'K',
'.-..' => 'L',
'--' => 'M',
'-.' => 'N',
'---' => 'O',
'.--.' => 'P',
'--.-' => 'Q',
'.-.' => 'R',
'...' => 'S',
'-' => 'T',
'..-' => 'U',
'...-' => 'V',
'.--' => 'W',
'-..-' => 'X',
'-.--' => 'Y',
'--..' => 'Z'
}.freeze

def decode_char(morse_char)
MORSE_CODE_DICT[morse_char.upcase]
end
morse_code = {
'.-' => 'A', '-...' => 'B', '-.-.' => 'C', '-..' => 'D',
'.' => 'E', '..-.' => 'F', '--.' => 'G', '....' => 'H',
'..' => 'I', '.---' => 'J', '-.-' => 'K', '.-..' => 'L',
'--' => 'M', '-.' => 'N', '---' => 'O', '.--.' => 'P',
'--.-' => 'Q', '.-.' => 'R', '...' => 'S', '-' => 'T',
'..-' => 'U', '...-' => 'V', '.--' => 'W', '-..-' => 'X',
'-.--' => 'Y', '--..' => 'Z'
}

puts decode_char('.--')
morse_code[morse_char]
end

def decode_word(morse_word)
decoded_word = ''
morse_chars = morse_word.split
morse_chars.map { |char| decode_char(char) }.join

morse_chars.each do |morse_char|
decoded_word += decode_char(morse_char)
end

decoded_word
end

puts decode_char('A')
def decode(message)
decoded_message = ''
morse_words = message.split(' ')

morse_words.each do |morse_word|
decoded_word = decode_word(morse_word)
decoded_message += "#{decoded_word} " unless decoded_word.empty?
end

def decode_message(morse_message)
morse_words = morse_message.split
morse_words.map { |word| decode_word(word) }.join
decoded_message.rstrip
end

morse_message = '.- -... --- -..- ..-. ..- .-.. .-.. --- ..-. .-. ..- -... .. . ...'
decoded_message = decode_message(morse_message)
# Decode the message from the old bottle
message = '.- -... --- -..- ..-. ..- .-.. .-.. --- ..-. .-. ..- -... .. . ...'
decoded_message = decode(message)
puts decoded_message

0 comments on commit 3bd71a7

Please sign in to comment.