├── Gemfile ├── README.md ├── .github └── workflows │ ├── tests.yml │ └── linters.yml ├── Gemfile.lock ├── morse_code.rb ├── LICENSE.md └── .rubocop.yml /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rubocop' 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kifle23/morse-code/HEAD/README.md -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | rspec: 7 | name: RSpec 8 | runs-on: ubuntu-22.04 9 | steps: 10 | - uses: actions/checkout@v3 11 | - uses: actions/setup-ruby@v1 12 | with: 13 | ruby-version: 3.1.x 14 | - name: Setup RSpec 15 | run: | 16 | [ -f Gemfile ] && bundle 17 | gem install --no-document rspec -v '>=3.0, < 4.0' 18 | - name: RSpec Report 19 | run: rspec --force-color --format documentation 20 | -------------------------------------------------------------------------------- /.github/workflows/linters.yml: -------------------------------------------------------------------------------- 1 | name: Linters 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | rubocop: 7 | name: Rubocop 8 | runs-on: ubuntu-22.04 9 | 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: actions/setup-ruby@v1 13 | with: 14 | ruby-version: ">=3.1.x" 15 | - name: Setup Rubocop 16 | run: | 17 | gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/ 18 | [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml 19 | - name: Rubocop Report 20 | run: rubocop --color 21 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | ast (2.4.2) 5 | json (2.6.3) 6 | language_server-protocol (3.17.0.3) 7 | parallel (1.23.0) 8 | parser (3.2.2.3) 9 | ast (~> 2.4.1) 10 | racc 11 | racc (1.7.1) 12 | rainbow (3.1.1) 13 | regexp_parser (2.8.1) 14 | rexml (3.2.5) 15 | rubocop (1.54.2) 16 | json (~> 2.3) 17 | language_server-protocol (>= 3.17.0) 18 | parallel (~> 1.10) 19 | parser (>= 3.2.2.3) 20 | rainbow (>= 2.2.2, < 4.0) 21 | regexp_parser (>= 1.8, < 3.0) 22 | rexml (>= 3.2.5, < 4.0) 23 | rubocop-ast (>= 1.28.0, < 2.0) 24 | ruby-progressbar (~> 1.7) 25 | unicode-display_width (>= 2.4.0, < 3.0) 26 | rubocop-ast (1.29.0) 27 | parser (>= 3.2.1.0) 28 | ruby-progressbar (1.13.0) 29 | unicode-display_width (2.4.2) 30 | 31 | PLATFORMS 32 | x64-mingw-ucrt 33 | 34 | DEPENDENCIES 35 | rubocop 36 | 37 | BUNDLED WITH 38 | 2.4.10 39 | -------------------------------------------------------------------------------- /morse_code.rb: -------------------------------------------------------------------------------- 1 | MORSE_CODE = { '.-' => 'A', '-...' => 'B', '-.-.' => 'C', '-..' => 'D', '.' => 'E', 2 | '..-.' => 'F', '--.' => 'G', '....' => 'H', '..' => 'I', '.---' => 'J', 3 | '-.-' => 'K', '.-..' => 'L', '--' => 'M', '-.' => 'N', '---' => 'O', 4 | '.--.' => 'P', '--.-' => 'Q', '.-.' => 'R', '...' => 'S', '-' => 'T', 5 | '..-' => 'U', '...-' => 'V', '.--' => 'W', '-..-' => 'X', '-.--' => 'Y', 6 | '--..' => 'Z' }.freeze 7 | 8 | def decode_morse_char(morse_char) 9 | MORSE_CODE[morse_char] || '' 10 | end 11 | 12 | def decode_morse_word(morse_word) 13 | morse_chars = morse_word.split 14 | morse_chars.map { |char| decode_morse_char(char) }.join 15 | end 16 | 17 | def decode_morse_message(morse_message) 18 | morse_words = morse_message.split(' ') 19 | morse_words.map { |word| decode_morse_word(word) }.join(' ') 20 | end 21 | 22 | message = '.- -... --- -..- ..-. ..- .-.. .-.. --- ..-. .-. ..- -... .. . ...' 23 | decoded_message = decode_morse_message(message) 24 | puts decoded_message 25 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Kifle Haile 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | NewCops: enable 3 | Exclude: 4 | - "Guardfile" 5 | - "Rakefile" 6 | - "node_modules/**/*" 7 | 8 | DisplayCopNames: true 9 | 10 | Layout/LineLength: 11 | Max: 120 12 | Metrics/MethodLength: 13 | Max: 20 14 | Metrics/AbcSize: 15 | Max: 50 16 | Metrics/ClassLength: 17 | Max: 150 18 | Metrics/BlockLength: 19 | IgnoredMethods: ['describe'] 20 | Max: 30 21 | 22 | 23 | Style/Documentation: 24 | Enabled: false 25 | Style/ClassAndModuleChildren: 26 | Enabled: false 27 | Style/EachForSimpleLoop: 28 | Enabled: false 29 | Style/AndOr: 30 | Enabled: false 31 | Style/DefWithParentheses: 32 | Enabled: false 33 | Style/FrozenStringLiteralComment: 34 | EnforcedStyle: never 35 | 36 | Layout/HashAlignment: 37 | EnforcedColonStyle: key 38 | Layout/ExtraSpacing: 39 | AllowForAlignment: false 40 | Layout/MultilineMethodCallIndentation: 41 | Enabled: true 42 | EnforcedStyle: indented 43 | Lint/RaiseException: 44 | Enabled: false 45 | Lint/StructNewOverride: 46 | Enabled: false 47 | Style/HashEachMethods: 48 | Enabled: false 49 | Style/HashTransformKeys: 50 | Enabled: false 51 | Style/HashTransformValues: 52 | Enabled: false 53 | --------------------------------------------------------------------------------