Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode a Morse code #1

Merged
merged 10 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Linters

on: pull_request

jobs:
rubocop:
name: Rubocop
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: actions/setup-ruby@v1
with:
ruby-version: ">=3.1.x"
- name: Setup Rubocop
run: |
gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/
[ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml
- name: Rubocop Report
run: rubocop --color
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Tests

on: pull_request

jobs:
rspec:
name: RSpec
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-ruby@v1
with:
ruby-version: 3.1.x
- name: Setup RSpec
run: |
[ -f Gemfile ] && bundle
gem install --no-document rspec -v '>=3.0, < 4.0'
- name: RSpec Report
run: rspec --force-color --format documentation
52 changes: 52 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
AllCops:
NewCops: enable
Exclude:
- "Guardfile"
- "Rakefile"
- "node_modules/**/*"

DisplayCopNames: true

Layout/LineLength:
Max: 120
Metrics/MethodLength:
Max: 20
Metrics/AbcSize:
Max: 50
Metrics/ClassLength:
Max: 150
Metrics/BlockLength:
IgnoredMethods: ['describe']
Max: 30


Style/Documentation:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Style/EachForSimpleLoop:
Enabled: false
Style/AndOr:
Enabled: false
Style/DefWithParentheses:
Enabled: false
Style/FrozenStringLiteralComment:
EnforcedStyle: never

Layout/HashAlignment:
EnforcedColonStyle: key
Layout/ExtraSpacing:
AllowForAlignment: false
Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented
Lint/RaiseException:
Enabled: false
Lint/StructNewOverride:
Enabled: false
Style/HashEachMethods:
Enabled: false
Style/HashTransformKeys:
Enabled: false
Style/HashTransformValues:
Enabled: false
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'rubocop', '>= 1.0', '< 2.0'
38 changes: 38 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
json (2.6.3)
language_server-protocol (3.17.0.3)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
racc (1.7.1)
rainbow (3.1.1)
regexp_parser (2.8.1)
rexml (3.2.5)
rubocop (1.54.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
unicode-display_width (2.4.2)

PLATFORMS
x64-mingw-ucrt

DEPENDENCIES
rubocop (>= 1.0, < 2.0)

BUNDLED WITH
2.4.17
196 changes: 194 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,194 @@
# Marse-Code-Decoder
The Ruby-based Morse Decoder is a handy utility designed to transform Morse code into easily readable text. By taking a string of Morse code as input, this tool facilitates communication using a combination of dots and dashes to represent letters, numbers, and symbols.
<a name="readme-top"></a>


<!-- TABLE OF CONTENTS -->

# 📗 Table of Contents

- [📖 About the Project](#about-project)
- [🛠 Built With](#built-with)
- [Tech Stack](#tech-stack)
- [Key Features](#key-features)
- [🚀 Schema Diagram](#live-demo)
- [💻 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)
- [📝 License](#license)

<!-- PROJECT DESCRIPTION -->

# 📖 [Marse Code Decoder] <a name="about-project"></a>

> **[Marse-Code-Decoder]** The Ruby-based Morse Decoder is a handy utility designed to transform Morse code into easily readable text. By taking a string of Morse code as input, this tool facilitates communication using a combination of dots and dashes to represent letters, numbers, and symbols.

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

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

<details>
<summary>Client</summary>
<ul>
<li></li>
</ul>
</details>

<details>
<summary>Server</summary>
<ul>
<li><a href="https://www.ruby-lang.org/en/">Ruby</a></li>
</ul>
</details>

<details>
<summary>Database</summary>
<ul>
<li></li>
</ul>
</details>

<!-- Features -->

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

- **[Decode morse codes]**
- **[words decoding]**
- **[Senteces decoding]**

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

<!-- LIVE DEMO -->

## 🚀 Schema Diagram <a name="live-demo"></a>

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

<!-- GETTING STARTED -->

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

To get a local copy up and running, follow these steps.

### Prerequisites

In order to run this project you need:

Example command:

```sh
Install Ruby
```

### Setup

Clone this repository to your desired folder:

```sh
cd my-folder
git clone https://github.com/ab-noori/Marse-Code-Decoder.git
```

### Install

Install this project with:

```sh
cd my-folder
git clone https://github.com/ab-noori/Marse-Code-Decoder.git
```

### Usage

To run the project, execute the following command:

```sh
cd my-folder
git clone https://github.com/ab-noori/Marse-Code-Decoder.git
```

### Run tests

To run tests, run the following command:

```sh
npm test
```

### Deployment

You can deploy this project using:

```sh
npm run deploy
```

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

<!-- AUTHORS -->

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

👤 **Abdul Ali Noori**

- GitHub: [@ab-noori](https://github.com/ab-noori)
- Twitter: [@AbdulAliNoori4](https://twitter.com/AbdulAliNoori4)
- LinkedIn: [abdulali-noori](https://www.linkedin.com/in/abdulali-noori)

👤 **Otmane Echchafyky**

- GitHub: [@otmaneechchafyky](https://github.com/otmaneechchafyky)
- Twitter: [@EchchafykyO](https://twitter.com/EchchafykyO)
- LinkedIn: [otmaneechchafyky](https://www.linkedin.com/in/otmane-echchafyky-125801248/)

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

<!-- FUTURE FEATURES -->

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

- [ ] **[Adding possibility ro decode numbers]**
- [ ] **[Creating UI so users can decode Morse codes]**

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

<!-- CONTRIBUTING -->

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

Contributions, issues, and feature requests are welcome!

Feel free to check the [issues page](https://github.com/ab-noori/Marse-Code-Decoder/issues).

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

<!-- SUPPORT -->

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

If you like this project, give it a star.

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

<!-- ACKNOWLEDGEMENTS -->

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

First, I would like to thank Microverse and my coding partners.

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


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

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

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

29 changes: 29 additions & 0 deletions morse_decoder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class MorseDecoder
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'
}.freeze

def self.decode_char(morse_char)
MORSE_CODE[morse_char] || ' '
end

def self.decode_word(morse_word)
morse_word.split.map { |morse_char| decode_char(morse_char) }.join
end

def self.decode_message(morse_message)
morse_words = morse_message.split(' ')
decoded_words = morse_words.map { |morse_word| decode_word(morse_word) }
decoded_words.join(' ')
end
end

# Test with the provided Morse code message
morse_message = '.- -... --- -..- ..-. ..- .-.. .-.. --- ..-. .-. ..- -... .. . ...'
decoded_message = MorseDecoder.decode_message(morse_message)
puts decoded_message
Loading