green_garden 0.1.1
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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +13 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +54 -0
- data/LICENSE.txt +21 -0
- data/README.md +102 -0
- data/Rakefile +6 -0
- data/bin/console +8 -0
- data/bin/green_garden +52 -0
- data/bin/setup +8 -0
- data/green_garden.gemspec +39 -0
- data/lib/green_garden.rb +33 -0
- data/lib/green_garden/comparer.rb +11 -0
- data/lib/green_garden/graph.rb +39 -0
- data/lib/green_garden/loader.rb +13 -0
- data/lib/green_garden/models/activity_tracker.rb +12 -0
- data/lib/green_garden/version.rb +5 -0
- metadata +122 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 29297ca3243831dc70447d9b91b78d14c2ae20203bd292695fe4d37d0787acf4
|
|
4
|
+
data.tar.gz: 57fade0f5a6e74d1fe9a0c249813e985f0b88644cea1183b8c8f52c307d98c88
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3ce61bc3721aecfadef1fa3ce6c2e900312e8fe4dd951a88247260225491f8c54049ca65af0493228f92fe91034858e6822c1933ba031aea56c36666a8c69540
|
|
7
|
+
data.tar.gz: c31cd052017305ddfa509e4612adf011f3f50e5832e5ab775325a3103ff3de162fd390fa2a993d97445cbc66b41cbb628531e703052c16a0bb73e148afa633f9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
language: ruby
|
|
2
|
+
cache: bundler
|
|
3
|
+
rvm:
|
|
4
|
+
- 2.6.6
|
|
5
|
+
before_install: gem install bundler -v 2.1.4
|
|
6
|
+
deploy:
|
|
7
|
+
provider: rubygems
|
|
8
|
+
api_key: "9cecfe4c096bd8443684cc6b09274e57"
|
|
9
|
+
on:
|
|
10
|
+
tags: true
|
|
11
|
+
branch: master
|
|
12
|
+
gem: green_garden
|
|
13
|
+
gemspec: green_garden.gemspec
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at nardonykolyszyn@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
# Specify your gem's dependencies in green_garden.gemspec
|
|
4
|
+
gemspec
|
|
5
|
+
|
|
6
|
+
gem "rake", "~> 12.0"
|
|
7
|
+
gem "rspec", "~> 3.0"
|
|
8
|
+
|
|
9
|
+
gem "rspec-expectations", "~> 3.9"
|
|
10
|
+
|
|
11
|
+
gem "rspec-json_expectations", "~> 2.2"
|
|
12
|
+
|
|
13
|
+
gem "rspec-collection_matchers", "~> 1.2"
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
green_garden (0.1.1)
|
|
5
|
+
colorize (~> 0.8.1)
|
|
6
|
+
dry-cli (~> 0.6.0)
|
|
7
|
+
oj (~> 3.10)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
coderay (1.1.3)
|
|
13
|
+
colorize (0.8.1)
|
|
14
|
+
concurrent-ruby (1.1.7)
|
|
15
|
+
diff-lcs (1.4.4)
|
|
16
|
+
dry-cli (0.6.0)
|
|
17
|
+
concurrent-ruby (~> 1.0)
|
|
18
|
+
method_source (1.0.0)
|
|
19
|
+
oj (3.10.14)
|
|
20
|
+
pry (0.13.1)
|
|
21
|
+
coderay (~> 1.1)
|
|
22
|
+
method_source (~> 1.0)
|
|
23
|
+
rake (12.3.3)
|
|
24
|
+
rspec (3.9.0)
|
|
25
|
+
rspec-core (~> 3.9.0)
|
|
26
|
+
rspec-expectations (~> 3.9.0)
|
|
27
|
+
rspec-mocks (~> 3.9.0)
|
|
28
|
+
rspec-collection_matchers (1.2.0)
|
|
29
|
+
rspec-expectations (>= 2.99.0.beta1)
|
|
30
|
+
rspec-core (3.9.2)
|
|
31
|
+
rspec-support (~> 3.9.3)
|
|
32
|
+
rspec-expectations (3.9.2)
|
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
34
|
+
rspec-support (~> 3.9.0)
|
|
35
|
+
rspec-json_expectations (2.2.0)
|
|
36
|
+
rspec-mocks (3.9.1)
|
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
38
|
+
rspec-support (~> 3.9.0)
|
|
39
|
+
rspec-support (3.9.3)
|
|
40
|
+
|
|
41
|
+
PLATFORMS
|
|
42
|
+
ruby
|
|
43
|
+
|
|
44
|
+
DEPENDENCIES
|
|
45
|
+
green_garden!
|
|
46
|
+
pry (~> 0.13.1)
|
|
47
|
+
rake (~> 12.0)
|
|
48
|
+
rspec (~> 3.0)
|
|
49
|
+
rspec-collection_matchers (~> 1.2)
|
|
50
|
+
rspec-expectations (~> 3.9)
|
|
51
|
+
rspec-json_expectations (~> 2.2)
|
|
52
|
+
|
|
53
|
+
BUNDLED WITH
|
|
54
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nardo Nykolyszyn
|
|
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,102 @@
|
|
|
1
|
+
# GreenGarden
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/nardonykolyszyn/green_garden)
|
|
4
|
+
|
|
5
|
+
*The land of green trees, where the magic happens and everything is possible, welcome to* **Green Garden** 🌳✨
|
|
6
|
+
-------------------------------------
|
|
7
|
+
|
|
8
|
+
**Why this name?**
|
|
9
|
+
|
|
10
|
+
These Trees are not regular ones, here is where the magic occurs, and where mysterious creatures called "Bugs" are on the prowl, be careful, and enjoy this new adventure. 🧙
|
|
11
|
+
|
|
12
|
+
**Purpose**
|
|
13
|
+
|
|
14
|
+
Green Garden was created with the purpose to teach algorithms by using multidimensional data-structures such as Hashes and Graphs.
|
|
15
|
+
|
|
16
|
+
**Capabilities**
|
|
17
|
+
|
|
18
|
+
*Before raising the blessed sword, get up that stick!*
|
|
19
|
+
|
|
20
|
+
Green Garden allows provides a powerful CLI tool to perform a set of operations with trees, additionally it's a Ruby gem that can be easily installed in your Rails or Ruby application.
|
|
21
|
+
|
|
22
|
+
- Compare two JSON files
|
|
23
|
+
|
|
24
|
+
**Coming soon**
|
|
25
|
+
- *[Label large datasets](https://whatis.techtarget.com/definition/data-labeling)*
|
|
26
|
+
- *Order datasets by a variety of options*
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
Add this line to your application's Gemfile:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
gem 'green_garden'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
And then execute:
|
|
37
|
+
|
|
38
|
+
$ bundle install
|
|
39
|
+
|
|
40
|
+
Or install it yourself as:
|
|
41
|
+
|
|
42
|
+
$ gem install green_garden
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
$ green_garden diff data/chicago.json data/seattle.json
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
> It returns "true" if both datasets are equal and "false" if not.
|
|
51
|
+
|
|
52
|
+
**Show current version**
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
$ green_garden --version
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Show help**
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
$ green_garden --help
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Performance
|
|
65
|
+
|
|
66
|
+
OJ was implemented to load heavy JSON files, feel free to use any big dataset you have, I guarantee you that there will not be any problem comparing them, recursive approach won't waste memory in unnecesary and repetitive operations.
|
|
67
|
+
|
|
68
|
+
**Fuzzing**
|
|
69
|
+
|
|
70
|
+
1. Download this sample dataset (https://github.com/lutangar/cities.json/blob/master/cities.json) [SIZE: 13MB]
|
|
71
|
+
|
|
72
|
+
2. Run
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
$ green_garden diff cities.json cities.json
|
|
76
|
+
```
|
|
77
|
+
--------------------------------
|
|
78
|
+
|
|
79
|
+

|
|
80
|
+
|
|
81
|
+
## Development
|
|
82
|
+
|
|
83
|
+
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.
|
|
84
|
+
|
|
85
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
86
|
+
|
|
87
|
+
## Contributing
|
|
88
|
+
|
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/green_garden. 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]/green_garden/blob/master/CODE_OF_CONDUCT.md).
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
95
|
+
|
|
96
|
+
## Code of Conduct
|
|
97
|
+
|
|
98
|
+
Everyone interacting in the GreenGarden project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/green_garden/blob/master/CODE_OF_CONDUCT.md).
|
|
99
|
+
|
|
100
|
+
# Author
|
|
101
|
+
|
|
102
|
+
*Nardo Nykolyszyn* - nardonykolyszyn (at) gmail
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/green_garden
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#!/usr/bin/env ruby
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "dry/cli"
|
|
6
|
+
require "green_garden"
|
|
7
|
+
require "colorize"
|
|
8
|
+
|
|
9
|
+
module GreenGarden
|
|
10
|
+
module CLI
|
|
11
|
+
module Commands
|
|
12
|
+
extend Dry::CLI::Registry
|
|
13
|
+
|
|
14
|
+
class Version < Dry::CLI::Command
|
|
15
|
+
desc "Show current version"
|
|
16
|
+
|
|
17
|
+
def call(*)
|
|
18
|
+
puts GreenGarden::VERSION
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Tree < Dry::CLI::Command
|
|
23
|
+
desc "Compare two datasets in (JSON) format"
|
|
24
|
+
|
|
25
|
+
argument :dataset_one, required: true, type: :string
|
|
26
|
+
argument :dataset_two, required: true, type: :string
|
|
27
|
+
|
|
28
|
+
example [
|
|
29
|
+
"data/chicago.json data/seattle.json"
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
def call(dataset_one:, dataset_two:)
|
|
33
|
+
begin
|
|
34
|
+
datasets_diff = GreenGarden::Tree.diff_between(dataset_one, dataset_two)
|
|
35
|
+
|
|
36
|
+
puts (datasets_diff ? "Datasets are equal".green : "Datasets are different".red)
|
|
37
|
+
rescue GreenGarden::Tree::DatasetNotFound
|
|
38
|
+
puts "Trees could not be loaded, please check files paths".red
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Register available options
|
|
44
|
+
|
|
45
|
+
register "version", Version, aliases: %w[v -v --version]
|
|
46
|
+
register "diff", Tree
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Initialize CLI
|
|
52
|
+
Dry::CLI.new(GreenGarden::CLI::Commands).call
|
data/bin/setup
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/green_garden/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'green_garden'
|
|
7
|
+
spec.version = GreenGarden::VERSION
|
|
8
|
+
spec.authors = %w[Nardo\ Nykolyszyn]
|
|
9
|
+
spec.email = %w[nardonykolyszyn@gmail.com]
|
|
10
|
+
|
|
11
|
+
spec.summary = 'The definitive gem to handle Trees in Ruby'
|
|
12
|
+
spec.description = 'Green Garden is the definitive Ruby gem to handle common Trees operations by using fancy code argued on Tree Traversal theorem.'
|
|
13
|
+
spec.homepage = 'https://github.com/nardonykolyszyn/green_garden.git'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/nardonykolyszyn/green_garden.git'
|
|
19
|
+
|
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
spec.require_paths = %w[lib]
|
|
27
|
+
|
|
28
|
+
spec.executables << 'green_garden'
|
|
29
|
+
|
|
30
|
+
## Dependencies
|
|
31
|
+
|
|
32
|
+
# Development
|
|
33
|
+
spec.add_development_dependency 'pry', '~> 0.13.1'
|
|
34
|
+
|
|
35
|
+
# Production
|
|
36
|
+
spec.add_dependency 'colorize', '~> 0.8.1'
|
|
37
|
+
spec.add_dependency 'dry-cli', '~> 0.6.0'
|
|
38
|
+
spec.add_dependency 'oj', '~> 3.10'
|
|
39
|
+
end
|
data/lib/green_garden.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'green_garden/comparer'
|
|
4
|
+
require 'green_garden/graph'
|
|
5
|
+
require 'green_garden/loader'
|
|
6
|
+
require 'green_garden/models/activity_tracker'
|
|
7
|
+
require 'green_garden/version'
|
|
8
|
+
|
|
9
|
+
module GreenGarden
|
|
10
|
+
class Tree
|
|
11
|
+
extend Loader
|
|
12
|
+
extend Graph
|
|
13
|
+
extend Comparer
|
|
14
|
+
class DatasetNotFound < StandardError
|
|
15
|
+
def initialize(msg = 'Dataset could not be loaded, please check file path')
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
class << self
|
|
20
|
+
def diff_between(tree_one, tree_two)
|
|
21
|
+
tree_one = load_json(tree_one)
|
|
22
|
+
tree_two = load_json(tree_two)
|
|
23
|
+
|
|
24
|
+
activity_one = travel_graph(tree_one, GreenGarden::ActivityTracker.new)
|
|
25
|
+
activity_two = travel_graph(tree_two, GreenGarden::ActivityTracker.new)
|
|
26
|
+
|
|
27
|
+
compare_activities(activity_one, activity_two)
|
|
28
|
+
rescue Errno::ENOENT
|
|
29
|
+
raise DatasetNotFound
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GreenGarden
|
|
4
|
+
module Comparer
|
|
5
|
+
def compare_activities(activity_one, activity_two)
|
|
6
|
+
(activity_one.shifts == activity_two.shifts) &&
|
|
7
|
+
(activity_one.parent_nodes == activity_two.parent_nodes) &&
|
|
8
|
+
(activity_one.children_nodes == activity_two.children_nodes)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Trees can be treated as graphs that perform very well for multidimensional operations
|
|
4
|
+
module GreenGarden
|
|
5
|
+
module Graph
|
|
6
|
+
# Pass any Tree you want to travel into
|
|
7
|
+
# Additionally you will need to pass a new activity_tracker to record information
|
|
8
|
+
def travel_graph(graph, current_activity)
|
|
9
|
+
graph.each do |node, children|
|
|
10
|
+
# Activity Tracker traits:
|
|
11
|
+
# shifts => Number of needed shifts to walk through the Tree.
|
|
12
|
+
# parent_nodes => All parent_nodes with their respective children structure type.
|
|
13
|
+
# children_nodes => Values of children items
|
|
14
|
+
current_activity.shifts += 1
|
|
15
|
+
current_activity.parent_nodes[node] = children.class
|
|
16
|
+
current_activity.children_nodes << record_children_as(children)
|
|
17
|
+
|
|
18
|
+
# When children exist we assume this node is a Hash otherwise it will be an Array.
|
|
19
|
+
if children.is_a?(Hash)
|
|
20
|
+
travel_graph(children, current_activity)
|
|
21
|
+
elsif children.is_a?(Array)
|
|
22
|
+
children.each { |child| travel_graph(child, current_activity) if child.is_a?(Hash) }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
current_activity
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def record_children_as(children)
|
|
29
|
+
case children.class
|
|
30
|
+
when String
|
|
31
|
+
children
|
|
32
|
+
when Array
|
|
33
|
+
children.flatten.map(&:values)
|
|
34
|
+
when Hash
|
|
35
|
+
children.values
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'oj'
|
|
4
|
+
|
|
5
|
+
# This modules provides a fast and non-disruptive way to load heavy JSON files
|
|
6
|
+
# Oj helps to carry on with this task by providing an optimized parsing and marshalling interface
|
|
7
|
+
module GreenGarden
|
|
8
|
+
module Loader
|
|
9
|
+
def load_json(file_path, read_mode = 'r')
|
|
10
|
+
File.open(file_path, read_mode) { |f| Oj.load(f.read) }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: green_garden
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nardo Nykolyszyn
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-09-08 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: pry
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.13.1
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.13.1
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: colorize
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.8.1
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.8.1
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: dry-cli
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.6.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.6.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: oj
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.10'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.10'
|
|
69
|
+
description: Green Garden is the definitive Ruby gem to handle common Trees operations
|
|
70
|
+
by using fancy code argued on Tree Traversal theorem.
|
|
71
|
+
email:
|
|
72
|
+
- nardonykolyszyn@gmail.com
|
|
73
|
+
executables:
|
|
74
|
+
- green_garden
|
|
75
|
+
extensions: []
|
|
76
|
+
extra_rdoc_files: []
|
|
77
|
+
files:
|
|
78
|
+
- ".gitignore"
|
|
79
|
+
- ".rspec"
|
|
80
|
+
- ".travis.yml"
|
|
81
|
+
- CODE_OF_CONDUCT.md
|
|
82
|
+
- Gemfile
|
|
83
|
+
- Gemfile.lock
|
|
84
|
+
- LICENSE.txt
|
|
85
|
+
- README.md
|
|
86
|
+
- Rakefile
|
|
87
|
+
- bin/console
|
|
88
|
+
- bin/green_garden
|
|
89
|
+
- bin/setup
|
|
90
|
+
- green_garden.gemspec
|
|
91
|
+
- lib/green_garden.rb
|
|
92
|
+
- lib/green_garden/comparer.rb
|
|
93
|
+
- lib/green_garden/graph.rb
|
|
94
|
+
- lib/green_garden/loader.rb
|
|
95
|
+
- lib/green_garden/models/activity_tracker.rb
|
|
96
|
+
- lib/green_garden/version.rb
|
|
97
|
+
homepage: https://github.com/nardonykolyszyn/green_garden.git
|
|
98
|
+
licenses:
|
|
99
|
+
- MIT
|
|
100
|
+
metadata:
|
|
101
|
+
homepage_uri: https://github.com/nardonykolyszyn/green_garden.git
|
|
102
|
+
source_code_uri: https://github.com/nardonykolyszyn/green_garden.git
|
|
103
|
+
post_install_message:
|
|
104
|
+
rdoc_options: []
|
|
105
|
+
require_paths:
|
|
106
|
+
- lib
|
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: 2.3.0
|
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
117
|
+
requirements: []
|
|
118
|
+
rubygems_version: 3.0.8
|
|
119
|
+
signing_key:
|
|
120
|
+
specification_version: 4
|
|
121
|
+
summary: The definitive gem to handle Trees in Ruby
|
|
122
|
+
test_files: []
|