diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 0000000..9984f01 --- /dev/null +++ b/.github/workflows/linters.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..61bcaab --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..4948d48 --- /dev/null +++ b/.rubocop.yml @@ -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 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..3fe9350 --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'rubocop', '>= 1.0', '< 2.0' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..afdb6e7 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/README.md b/README.md index 1b96a7f..73e0b99 100644 --- a/README.md +++ b/README.md @@ -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. + + + + + +# 📗 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) + + + +# 📖 [Marse Code Decoder] + +> **[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 + +### Tech Stack + +
+ Client + +
+ +
+ Server + +
+ +
+Database + +
+ + + +### Key Features + +- **[Decode morse codes]** +- **[words decoding]** +- **[Senteces decoding]** + +

(back to top)

+ + + +## 🚀 Schema Diagram + +

(back to top)

+ + + +## 💻 Getting Started + +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 +``` + +

(back to top)

+ + + +## 👥 Authors + +👤 **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/) + +

(back to top)

+ + + +## 🔭 Future Features + +- [ ] **[Adding possibility ro decode numbers]** +- [ ] **[Creating UI so users can decode Morse codes]** + +

(back to top)

+ + + +## 🤝 Contributing + + Contributions, issues, and feature requests are welcome! + + Feel free to check the [issues page](https://github.com/ab-noori/Marse-Code-Decoder/issues). + +

(back to top)

+ + + +## ⭐️ Show your support + + If you like this project, give it a star. + +

(back to top)

+ + + +## 🙏 Acknowledgments + + First, I would like to thank Microverse and my coding partners. + +

(back to top)

+ + +## 📝 License + +This project is [MIT](./LICENSE) licensed. + +

(back to top)

+ diff --git a/morse_decoder.rb b/morse_decoder.rb new file mode 100644 index 0000000..0408cd1 --- /dev/null +++ b/morse_decoder.rb @@ -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