mutants 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: e878ee5bee99966ea68cc31caf6874d4164ec31da4d2407b287fd239bfd335d7
4
+ data.tar.gz: 70bfb2f84c7b7a2030ef19c1746bcb2de3acc1efd40cd6c200dbf78f94241164
5
+ SHA512:
6
+ metadata.gz: 5d9f109aefe5eb3922dc341d78a733b9941feb9d4b6625affab038127cda4ee4dd599665db7993e1883ff5dbdd0aa2d2074e16591d5dac8b040b3750594905cc
7
+ data.tar.gz: 0c4afb1572a7a540c928b530e6f5eccb192826d5ce522b65a65e4308c2282472161a276ee4480e4f53fc254ef98edc201ad92f495fc740712bb6ec6f0404c1d8
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-03-19
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in mutants.gemspec
6
+ gemspec
7
+
8
+ ruby '3.0.0'
9
+
10
+ gem 'rake', '~> 13.0'
11
+
12
+ gem 'rspec', '~> 3.0'
13
+
14
+ gem 'rubocop', '~> 1.26'
data/Gemfile.lock ADDED
@@ -0,0 +1,118 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mutants (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionpack (7.0.2.3)
10
+ actionview (= 7.0.2.3)
11
+ activesupport (= 7.0.2.3)
12
+ rack (~> 2.0, >= 2.2.0)
13
+ rack-test (>= 0.6.3)
14
+ rails-dom-testing (~> 2.0)
15
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
16
+ actionview (7.0.2.3)
17
+ activesupport (= 7.0.2.3)
18
+ builder (~> 3.1)
19
+ erubi (~> 1.4)
20
+ rails-dom-testing (~> 2.0)
21
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
22
+ activesupport (7.0.2.3)
23
+ concurrent-ruby (~> 1.0, >= 1.0.2)
24
+ i18n (>= 1.6, < 2)
25
+ minitest (>= 5.1)
26
+ tzinfo (~> 2.0)
27
+ ast (2.4.2)
28
+ builder (3.2.4)
29
+ concurrent-ruby (1.1.9)
30
+ crass (1.0.6)
31
+ diff-lcs (1.5.0)
32
+ erubi (1.10.0)
33
+ i18n (1.10.0)
34
+ concurrent-ruby (~> 1.0)
35
+ loofah (2.15.0)
36
+ crass (~> 1.0.2)
37
+ nokogiri (>= 1.5.9)
38
+ method_source (1.0.0)
39
+ minitest (5.15.0)
40
+ nokogiri (1.13.3-x86_64-linux)
41
+ racc (~> 1.4)
42
+ parallel (1.22.0)
43
+ parser (3.1.1.0)
44
+ ast (~> 2.4.1)
45
+ racc (1.6.0)
46
+ rack (2.2.3)
47
+ rack-test (1.1.0)
48
+ rack (>= 1.0, < 3)
49
+ rails-dom-testing (2.0.3)
50
+ activesupport (>= 4.2.0)
51
+ nokogiri (>= 1.6)
52
+ rails-html-sanitizer (1.4.2)
53
+ loofah (~> 2.3)
54
+ railties (7.0.2.3)
55
+ actionpack (= 7.0.2.3)
56
+ activesupport (= 7.0.2.3)
57
+ method_source
58
+ rake (>= 12.2)
59
+ thor (~> 1.0)
60
+ zeitwerk (~> 2.5)
61
+ rainbow (3.1.1)
62
+ rake (13.0.6)
63
+ regexp_parser (2.2.1)
64
+ rexml (3.2.5)
65
+ rspec (3.11.0)
66
+ rspec-core (~> 3.11.0)
67
+ rspec-expectations (~> 3.11.0)
68
+ rspec-mocks (~> 3.11.0)
69
+ rspec-core (3.11.0)
70
+ rspec-support (~> 3.11.0)
71
+ rspec-expectations (3.11.0)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.11.0)
74
+ rspec-mocks (3.11.0)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.11.0)
77
+ rspec-rails (5.1.1)
78
+ actionpack (>= 5.2)
79
+ activesupport (>= 5.2)
80
+ railties (>= 5.2)
81
+ rspec-core (~> 3.10)
82
+ rspec-expectations (~> 3.10)
83
+ rspec-mocks (~> 3.10)
84
+ rspec-support (~> 3.10)
85
+ rspec-support (3.11.0)
86
+ rubocop (1.26.0)
87
+ parallel (~> 1.10)
88
+ parser (>= 3.1.0.0)
89
+ rainbow (>= 2.2.2, < 4.0)
90
+ regexp_parser (>= 1.8, < 3.0)
91
+ rexml
92
+ rubocop-ast (>= 1.16.0, < 2.0)
93
+ ruby-progressbar (~> 1.7)
94
+ unicode-display_width (>= 1.4.0, < 3.0)
95
+ rubocop-ast (1.16.0)
96
+ parser (>= 3.1.1.0)
97
+ ruby-progressbar (1.11.0)
98
+ thor (1.2.1)
99
+ tzinfo (2.0.4)
100
+ concurrent-ruby (~> 1.0)
101
+ unicode-display_width (2.1.0)
102
+ zeitwerk (2.5.4)
103
+
104
+ PLATFORMS
105
+ x86_64-linux
106
+
107
+ DEPENDENCIES
108
+ mutants!
109
+ rake (~> 13.0)
110
+ rspec (~> 3.0)
111
+ rspec-rails
112
+ rubocop (~> 1.26)
113
+
114
+ RUBY VERSION
115
+ ruby 3.0.0p0
116
+
117
+ BUNDLED WITH
118
+ 2.3.9
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 TODO: Write your name
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Mutants
2
+
3
+ ![ruby](https://github.com/vurokrazia/mutants/actions/workflows/ruby.yml/badge.svg)
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mutants`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ This library helps you detect if a DNA sequence belongs to a mutant or not.
8
+
9
+ ## Installation
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add mutants
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install mutants
18
+
19
+ ## Usage
20
+
21
+ First step is has a sequence DNA:
22
+ ```ruby
23
+ sequence = %w[
24
+ ATAG
25
+ TAAA
26
+ AGAG
27
+ ACAA
28
+ ]
29
+
30
+ ```
31
+ The second step is to create an instance of the validations class with the sequence to validate, activate the flags to evaluate in the case:
32
+ ```ruby
33
+ builder = Mutants::Validations.new
34
+ .set_sequence(
35
+ sequence
36
+ )
37
+ .set_validate_sizes(true)
38
+ .set_validate_dna(true)
39
+ ```
40
+ If you have an invalid sequence by dimension sizes, it returns with this error:
41
+ ```ruby
42
+ Mutants::Validations::InvalidSizeDnaSequence
43
+ ```
44
+ If you have an invalid sequence due to letters in the DNA AGTC sequence, it returns with this error:
45
+ ```ruby
46
+ Mutants::Validations::InvalidDNA
47
+ ```
48
+ The las step is pass the builder to dectector class and execute isMutant with the sequence and check the result.
49
+ ```ruby
50
+ Mutants::Detector.new(builder).isMutant(sequence)
51
+ ```
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mutants. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/mutants/blob/master/CODE_OF_CONDUCT.md).
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
66
+
67
+ ## Code of Conduct
68
+
69
+ Everyone interacting in the Mutants project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mutants/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/dev.dockerfile ADDED
@@ -0,0 +1,31 @@
1
+ FROM ruby:3.0.0
2
+ RUN curl https://deb.nodesource.com/setup_14.x | bash
3
+ RUN curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
4
+ RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
5
+ # Install libraries
6
+ RUN apt-get update && apt-get install -y \
7
+ build-essential \
8
+ nodejs \
9
+ yarn \
10
+ libnss3-dev
11
+ # add user
12
+ RUN useradd developer
13
+ # Create folder developer
14
+ RUN mkdir -p /home/developer
15
+ # set folder
16
+ WORKDIR /home
17
+ # set permission to folderexit
18
+ RUN chown -R developer:developer developer
19
+ RUN chmod 755 developer
20
+ # set user
21
+ USER developer
22
+ # Create folder app
23
+ RUN mkdir -p /home/developer/app
24
+ # use folder app
25
+ WORKDIR /home/developer/app
26
+ # Copy the main app
27
+ COPY ./ .
28
+ RUN gem install bundler:2.3.9
29
+ # run console
30
+ # CMD ["entrypoint.sh"]
31
+ CMD ruby -e "loop do ; end"
@@ -0,0 +1,12 @@
1
+ version: "3.2"
2
+ volumes:
3
+ bundle_gems:
4
+ services:
5
+ app:
6
+ restart: always
7
+ build:
8
+ context: .
9
+ dockerfile: dev.dockerfile
10
+ volumes:
11
+ - .:/home/developer/app
12
+ - bundle_gems:/usr/local/bundle
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutants
4
+ module Configuration
5
+ MIN_SEQUENCES_TO_BE_MUTANT = 2
6
+ COUNTER_SEQUENCES = 4
7
+ SEQUENCE = 'AGTC'
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutants
4
+ class Detector
5
+ attr_reader :builder
6
+
7
+ def initialize(builder)
8
+ @builder = builder
9
+ end
10
+
11
+ def isMutant(sequence)
12
+ validate
13
+ return true if dna.horizontal(sequence) ||
14
+ dna.vertical(sequence) ||
15
+ dna.bottom_diagonals_from_left_read_without_main_diagonal(sequence) ||
16
+ dna.bottom_diagonals_from_right_read_without_main_diagonal(sequence) ||
17
+ dna.top_diagonals_from_left_read_with_main_diagonal(sequence) ||
18
+ dna.top_diagonals_from_right_read_with_main_diagonal(sequence)
19
+ end
20
+
21
+ private
22
+
23
+ def dna
24
+ @dna ||= Mutants::Dna.new
25
+ end
26
+
27
+ def validate
28
+ builder
29
+ .validate
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,196 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutants
4
+ class Dna
5
+ attr_reader :sequence, :counter, :last_character
6
+
7
+ def initialize
8
+ @counter = 0
9
+ end
10
+
11
+ def horizontal(sequence)
12
+ @sequence = sequence
13
+ row = 0
14
+ loop do
15
+ break unless row < sequence.length
16
+
17
+ @last_character = sequence[row][0]
18
+ return true if read_horizontal_or_vertical(Mutants::Orientation::HORIZONTAL,
19
+ last_character,
20
+ row)
21
+
22
+ row += 1
23
+ end
24
+
25
+ false
26
+ end
27
+
28
+ def vertical(sequence)
29
+ @sequence = sequence
30
+ col = 0
31
+ loop do
32
+ break unless col < sequence.length
33
+
34
+ @last_character = sequence[0][col]
35
+ return true if read_horizontal_or_vertical(Mutants::Orientation::VERTICAL,
36
+ last_character,
37
+ col)
38
+
39
+ col += 1
40
+ end
41
+
42
+ false
43
+ end
44
+
45
+ def bottom_diagonals_from_left_read_without_main_diagonal(sequence)
46
+ @sequence = sequence
47
+ row = 1
48
+ loop do
49
+ break unless row < sequence.length
50
+
51
+ @last_character = sequence[row][0]
52
+
53
+ return true if read_diagonals(Mutants::Orientation::FROM_LEFT,
54
+ Mutants::Orientation::BELOW_MAIN_DIAGONAL,
55
+ row, 0)
56
+
57
+ row += 1
58
+ end
59
+
60
+ false
61
+ end
62
+
63
+ def bottom_diagonals_from_right_read_without_main_diagonal(sequence)
64
+ @sequence = sequence
65
+ row = 1
66
+ loop do
67
+ break unless row < sequence.length
68
+
69
+ @last_character = sequence[row][sequence.length - 1]
70
+ return true if read_diagonals(Mutants::Orientation::FROM_RIGHT,
71
+ Mutants::Orientation::BELOW_MAIN_DIAGONAL,
72
+ row,
73
+ sequence.length - 1)
74
+
75
+ row += 1
76
+ end
77
+
78
+ false
79
+ end
80
+
81
+ def top_diagonals_from_left_read_with_main_diagonal(sequence)
82
+ @sequence = sequence
83
+ col = 0
84
+ loop do
85
+ break unless col < sequence.length
86
+
87
+ @last_character = sequence[0][col]
88
+ return true if read_diagonals(Mutants::Orientation::FROM_LEFT,
89
+ Mutants::Orientation::ABOVE_MAIN_DIAGONAL_INCLUDING,
90
+ 0,
91
+ col)
92
+
93
+ col += 1
94
+ end
95
+
96
+ false
97
+ end
98
+
99
+ def top_diagonals_from_right_read_with_main_diagonal(sequence)
100
+ @sequence = sequence
101
+ col = 1
102
+ loop do
103
+ break unless col < sequence.length
104
+
105
+ @last_character = sequence[0][sequence.length - col]
106
+ return true if read_diagonals(Mutants::Orientation::FROM_RIGHT,
107
+ Mutants::Orientation::ABOVE_MAIN_DIAGONAL_INCLUDING,
108
+ 0,
109
+ sequence.length - col)
110
+
111
+ col += 1
112
+ end
113
+
114
+ false
115
+ end
116
+
117
+ def read_horizontal_or_vertical(direction, initial_character, index)
118
+ characters_count = 1
119
+ last_character = initial_character
120
+ current_character = nil
121
+ subindex = 1
122
+ while sequence.length - subindex + characters_count >= 4 && subindex < sequence.length
123
+ current_character = if Mutants::Orientation::HORIZONTAL == direction
124
+ sequence[index][subindex]
125
+ else
126
+ sequence[subindex][index]
127
+ end
128
+ if last_character == current_character
129
+ characters_count += 1
130
+ if characters_count == Mutants::Configuration::COUNTER_SEQUENCES
131
+ @counter += 1
132
+ characters_count = 0
133
+ if counter >= Mutants::Configuration::MIN_SEQUENCES_TO_BE_MUTANT
134
+ # If a find the minimum sequences to determine if it is Mutant, I finish the search.
135
+ return true
136
+ end
137
+ end
138
+ else
139
+ last_character = current_character
140
+ characters_count = 1
141
+ end
142
+ subindex += 1
143
+ end
144
+ false
145
+ end
146
+
147
+ def read_diagonals(read_direction, read_type, base_n, base_m)
148
+ offset = 1
149
+
150
+ characters_count = 1
151
+
152
+ last_character = sequence[base_n][base_m]
153
+ current_character = nil
154
+
155
+ # This condition is valid when you can still read below the main diagonal
156
+ bottom_read_condition = base_n + offset < sequence.length
157
+
158
+ # This condition is valid when you can still read from the main diagonal to the top.
159
+ top_read_condition = (read_direction.eql?(Mutants::Orientation::FROM_LEFT) && base_m + offset < sequence.length ||
160
+ read_direction.eql?(Mutants::Orientation::FROM_RIGHT) && base_m - offset >= 0)
161
+
162
+ # From the verification of the previous conditions it decides if it is correct to continue reading the diagonal.
163
+ while (read_type.eql?(Mutants::Orientation::ABOVE_MAIN_DIAGONAL_INCLUDING) && top_read_condition) ||
164
+ (read_type.eql?(Mutants::Orientation::BELOW_MAIN_DIAGONAL) && bottom_read_condition)
165
+
166
+ current_character = if read_direction.eql?(Mutants::Orientation::FROM_LEFT)
167
+ sequence[base_n + offset][base_m + offset]
168
+ else
169
+ sequence[base_n + offset][base_m - offset]
170
+ end
171
+ if last_character == current_character
172
+ characters_count += 1
173
+ if characters_count == Mutants::Configuration::COUNTER_SEQUENCES
174
+ @counter += 1
175
+ characters_count = 0
176
+ # If a find the minimum sequences to determine if it is Mutant, I finish the search.
177
+ return true if counter >= Mutants::Configuration::MIN_SEQUENCES_TO_BE_MUTANT
178
+ end
179
+ else
180
+ last_character = current_character
181
+ characters_count = 1
182
+ end
183
+
184
+ offset += 1
185
+
186
+ # I will verify the read conditions.
187
+ bottom_read_condition = base_n + offset < sequence.length
188
+
189
+ top_read_condition = (read_direction.eql?(Mutants::Orientation::FROM_LEFT) && base_m + offset < sequence.length ||
190
+ read_direction.eql?(Mutants::Orientation::FROM_RIGHT) && base_m - offset >= 0)
191
+ end
192
+ # The subject is Human
193
+ false
194
+ end
195
+ end
196
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutants
4
+ module Orientation
5
+ HORIZONTAL = 0
6
+ VERTICAL = 1
7
+ BELOW_MAIN_DIAGONAL = 2
8
+ ABOVE_MAIN_DIAGONAL_INCLUDING = 3
9
+ FROM_RIGHT = 4
10
+ FROM_LEFT = 5
11
+ end
12
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutants
4
+ class Validations
5
+ attr_reader :sequence, :validate_sizes, :validate_dna
6
+
7
+ class NotAnArraySequence < StandardError; end
8
+ class InvalidSizeDnaSequence < StandardError; end
9
+ class InvalidDNA < StandardError; end
10
+
11
+ def initialize
12
+ @sequence = []
13
+ end
14
+
15
+ def set_sequence(sequence)
16
+ @sequence = valid_sequence?(sequence)
17
+ self
18
+ end
19
+
20
+ def set_validate_sizes(validate_sizes)
21
+ @validate_sizes = validate_sizes
22
+ self
23
+ end
24
+
25
+ def set_validate_dna(validate_dna)
26
+ @validate_dna = validate_dna
27
+ self
28
+ end
29
+
30
+ def validate
31
+ sequence.each do |dna|
32
+ valid_sizes? dna
33
+ valid_dna? dna
34
+ end
35
+
36
+ true
37
+ end
38
+
39
+ private
40
+
41
+ def valid_sizes?(dna)
42
+ return unless validate_sizes
43
+ return if dna.length == sequence.length
44
+
45
+ raise Mutants::Validations::InvalidSizeDnaSequence
46
+ end
47
+
48
+ def valid_dna?(dna)
49
+ return unless validate_dna
50
+ return if dna.scan(/[#{Mutants::Configuration::SEQUENCE}]/).size == dna.size
51
+
52
+ raise Mutants::Validations::InvalidDNA
53
+ end
54
+
55
+ def valid_sequence?(sequence)
56
+ return sequence if sequence.is_a?(Array) &&
57
+ sequence.size >= Mutants::Configuration::COUNTER_SEQUENCES
58
+
59
+ raise Mutants::Validations::NotAnArraySequence
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutants
4
+ VERSION = '0.1.0'
5
+ end
data/lib/mutants.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'mutants/version'
4
+
5
+ require 'mutants/configuration'
6
+ require 'mutants/orientation'
7
+ require 'mutants/validations'
8
+ require 'mutants/detector'
9
+ require 'mutants/dna'
data/sig/mutants.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Mutants
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mutants
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jesus Martinez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-rails
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: Magneto needs my help
28
+ email:
29
+ - jesus.alberto.vk@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".ruby-version"
36
+ - CHANGELOG.md
37
+ - CODE_OF_CONDUCT.md
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - dev.dockerfile
44
+ - docker-compose.yml
45
+ - lib/mutants.rb
46
+ - lib/mutants/configuration.rb
47
+ - lib/mutants/detector.rb
48
+ - lib/mutants/dna.rb
49
+ - lib/mutants/orientation.rb
50
+ - lib/mutants/validations.rb
51
+ - lib/mutants/version.rb
52
+ - sig/mutants.rbs
53
+ homepage: https://github.com/vurokrazia/mutants
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://github.com/vurokrazia/mutants
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 3.0.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.2.3
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Mutans
77
+ test_files: []