tog_caesar 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6c756f618b203603dd94d35c2fba8dce42c45934d62d50b138917385b2f2c0ba
4
+ data.tar.gz: 4b5218f7b893f794fc09234a43f0b147fd4eca739f36f435019128bc6175811d
5
+ SHA512:
6
+ metadata.gz: '09f94f8080509fd1b555a498c58dc36f611ca8fd55cdba1fd09e6b97690689e5a48aea1df67508b7d949f8cbe9b7c1daa4f5c3f699d7027d67348f02e71b3a15'
7
+ data.tar.gz: 6e0385e25535cca8e3d808e1717cc84897678e4aef72718aaeca336f2ffacbf2a4289c68e1243fe48c9c24d9d8cacaa60b49fb57a30c493fcf2eb4b9548b7930
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2022 Ian Johnson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Odin Caesar Cipher
2
+
3
+ [Project Link](https://www.theodinproject.com/paths/full-stack-ruby-on-rails/courses/ruby-programming/lessons/caesar-cipher)
4
+
5
+ ## Run the binary
6
+
7
+ ```sh
8
+ bin/caesar "What a string!" 5
9
+ ```
10
+
11
+ ## Run the tests
12
+
13
+ ```sh
14
+ bundle install && bundle exec rspec
15
+ ```
16
+
17
+ ## Use the library
18
+
19
+ ```ruby
20
+ Caesar.cipher("What a string!", 5)
21
+ ```
22
+
23
+ ## Use the gem
24
+
25
+ **Gemfile**
26
+
27
+ ```ruby
28
+ source 'https://rubygems.org'
29
+
30
+ gem 'tog_caesar'
31
+ ```
32
+
33
+ **Usage**
34
+
35
+ ```ruby
36
+ require 'tog_caesar'
37
+
38
+ Caesar.cipher("What a string!", 5)
39
+ ```
data/bin/caesar ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/caesar.rb'
4
+
5
+ args = ARGV
6
+
7
+ unless args.length < 2
8
+ puts Caesar.cipher(args[0], args[1].to_i)
9
+ end
data/lib/caesar.rb ADDED
@@ -0,0 +1,9 @@
1
+ class Caesar
2
+ LOWER = ("a".."z").to_a
3
+ UPPER = ("A".."Z").to_a
4
+
5
+ def self.cipher(str, num=13)
6
+ str.tr(LOWER.join, LOWER.rotate(num).join)
7
+ .tr(UPPER.join, UPPER.rotate(num).join)
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../lib/caesar.rb'
2
+
3
+ RSpec.describe Caesar, ".cipher" do
4
+ context "with a string and a number" do
5
+ it "outputs the message with the correct shift" do
6
+ expect(Caesar.cipher('message', 5)).to eq 'rjxxflj'
7
+ end
8
+
9
+ it "ignores special characters" do
10
+ expect(Caesar.cipher('message!', 5)).to eq 'rjxxflj!'
11
+ end
12
+ end
13
+
14
+ context "with a string" do
15
+ it "outputs the message with the default shift" do
16
+ expect(Caesar.cipher('message')).to eq 'zrffntr'
17
+ end
18
+
19
+ it "ignores special characters" do
20
+ expect(Caesar.cipher('message!')).to eq 'zrffntr!'
21
+ end
22
+ end
23
+
24
+ context "without a string" do
25
+ it "raises an ArgumentError" do
26
+ expect { Caesar.cipher() }.to raise_error(ArgumentError)
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tog_caesar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ian Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: |-
28
+ # Odin Caesar Cipher
29
+
30
+ [Project Link](https://www.theodinproject.com/paths/full-stack-ruby-on-rails/courses/ruby-programming/lessons/caesar-cipher)
31
+
32
+ ## Run the binary
33
+
34
+ ```sh
35
+ bin/caesar "What a string!" 5
36
+ ```
37
+
38
+ ## Run the tests
39
+
40
+ ```sh
41
+ bundle install && bundle exec rspec
42
+ ```
43
+
44
+ ## Use the library
45
+
46
+ ```ruby
47
+ Caesar.cipher("What a string!", 5)
48
+ ```
49
+
50
+ ## Use the gem
51
+
52
+ **Gemfile**
53
+
54
+ ```ruby
55
+ source 'https://rubygems.org'
56
+
57
+ gem 'tog_caesar'
58
+ ```
59
+
60
+ **Usage**
61
+
62
+ ```ruby
63
+ require 'tog_caesar'
64
+
65
+ Caesar.cipher("What a string!", 5)
66
+ ```
67
+ email: tacoda@hey.com
68
+ executables:
69
+ - caesar
70
+ extensions: []
71
+ extra_rdoc_files: []
72
+ files:
73
+ - LICENSE
74
+ - README.md
75
+ - bin/caesar
76
+ - lib/caesar.rb
77
+ - spec/caesar_spec.rb
78
+ homepage: https://github.com/tacoda/odin-caesar-cipher
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '1.9'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.2.22
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Ceasar Cipher
101
+ test_files:
102
+ - spec/caesar_spec.rb