spaceship_mission_simulator 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 +7 -0
- data/.gitignore +7 -0
- data/.rubocop.yml +13 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +46 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +27 -0
- data/bin/setup +6 -0
- data/lib/spaceship_mission_simulator.rb +14 -0
- data/lib/spaceship_mission_simulator/event.rb +10 -0
- data/lib/spaceship_mission_simulator/interactors/identify_planet.rb +23 -0
- data/lib/spaceship_mission_simulator/interactors/simulate.rb +72 -0
- data/lib/spaceship_mission_simulator/interactors/simulate_event.rb +58 -0
- data/lib/spaceship_mission_simulator/interactors/validate_event_data.rb +18 -0
- data/lib/spaceship_mission_simulator/interactors/validate_event_state.rb +13 -0
- data/lib/spaceship_mission_simulator/interactors/validate_finish_event.rb +14 -0
- data/lib/spaceship_mission_simulator/interactors/validate_initial_weight.rb +11 -0
- data/lib/spaceship_mission_simulator/interactors/validate_path_consistency.rb +12 -0
- data/lib/spaceship_mission_simulator/interactors/validate_raw_path.rb +11 -0
- data/lib/spaceship_mission_simulator/interactors/validate_start_event.rb +14 -0
- data/lib/spaceship_mission_simulator/path.rb +19 -0
- data/lib/spaceship_mission_simulator/planet.rb +18 -0
- data/lib/spaceship_mission_simulator/simulation_result.rb +25 -0
- data/lib/spaceship_mission_simulator/version.rb +3 -0
- data/spaceship_mission_simulator.gemspec +31 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e0cf4e800523c2d52a724cf7cd5316f325d8a7c6de6edebb6a1e39da6a4e821
|
4
|
+
data.tar.gz: dfd4323e4a7f01082d1fe9d3e9cd4928ffc4de7e0b165e4be273562653074046
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 50461ac62dc7ccf092a154b91b36c44935fce99bcb9432128feef7927285728f40d3d0debf7c0d754f7295fed18e168c01c8a2d20001e691259fc4d666e49967
|
7
|
+
data.tar.gz: 6c2eb6d78626345c4843df427de4750f8729cb03824b6acd37857fd11ef61d5c60c5b1efdba1723e6804786a9826b091e9511d504fd0f63abb3835c6daa6f758
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
spaceship_fuel_calc
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
spaceship_mission_simulator (0.1.0)
|
5
|
+
awesome_print (= 1.8.0)
|
6
|
+
interactor (= 3.1.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.1)
|
12
|
+
awesome_print (1.8.0)
|
13
|
+
interactor (3.1.2)
|
14
|
+
minitest (5.14.2)
|
15
|
+
parallel (1.19.2)
|
16
|
+
parser (2.7.1.4)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
rainbow (3.0.0)
|
19
|
+
rake (12.3.3)
|
20
|
+
regexp_parser (1.7.1)
|
21
|
+
rexml (3.2.4)
|
22
|
+
rubocop (0.90.0)
|
23
|
+
parallel (~> 1.10)
|
24
|
+
parser (>= 2.7.1.1)
|
25
|
+
rainbow (>= 2.2.2, < 4.0)
|
26
|
+
regexp_parser (>= 1.7)
|
27
|
+
rexml
|
28
|
+
rubocop-ast (>= 0.3.0, < 1.0)
|
29
|
+
ruby-progressbar (~> 1.7)
|
30
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
31
|
+
rubocop-ast (0.3.0)
|
32
|
+
parser (>= 2.7.1.4)
|
33
|
+
ruby-progressbar (1.10.1)
|
34
|
+
unicode-display_width (1.7.0)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
minitest (~> 5.0)
|
41
|
+
rake (~> 12.0)
|
42
|
+
rubocop (~> 0.8)
|
43
|
+
spaceship_mission_simulator!
|
44
|
+
|
45
|
+
BUNDLED WITH
|
46
|
+
2.1.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 acidwizard
|
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,77 @@
|
|
1
|
+
# SpaceshipFuelCalc
|
2
|
+
|
3
|
+
The goal of this gem is to calculate fuel to launch from one planet of the Solar System, and land to another planet of the Solar System, depending on the flight route.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'spaceship_mission_simulator'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install spaceship_mission_simulator
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'spaceship_mission_simulator'
|
25
|
+
|
26
|
+
class SpaceshipCommandCenter
|
27
|
+
include SpaceshipMissionSimulator
|
28
|
+
|
29
|
+
# ...
|
30
|
+
end
|
31
|
+
|
32
|
+
scc = SpaceshipCommandCenter.new
|
33
|
+
|
34
|
+
raw_path = [[:launch, 9.807], [:land, 1.62], [:launch, 1.62], [:land, 9.807]]
|
35
|
+
scc.simulate_spaceship_mission! 28_801, raw_path
|
36
|
+
|
37
|
+
# => #<Interactor::Context result=#<struct SpaceshipMissionSimulator::SimulationResult initial_weight=28801, total_fuel_weight=51898, path=#<struct SpaceshipMissionSimulator::Path raw_data=[[:launch, 9.807], [:land, 1.62], [:launch, 1.62], [:land, 9.807]], events=[#<struct SpaceshipMissionSimulator::Event state=:launch, planet=#<struct SpaceshipMissionSimulator::Planet gravity=9.807, key=:earth, name="Earth">, reserved_fuel_weight=18910, fuel_weight=32988>, #<struct SpaceshipMissionSimulator::Event state=:land, planet=#<struct SpaceshipMissionSimulator::Planet gravity=1.62, key=:moon, name="Moon">, reserved_fuel_weight=16448, fuel_weight=2462>, #<struct SpaceshipMissionSimulator::Event state=:launch, planet=#<struct SpaceshipMissionSimulator::Planet gravity=1.62, key=:moon, name="Moon">, reserved_fuel_weight=13447, fuel_weight=3001>, #<struct SpaceshipMissionSimulator::Event state=:land, planet=#<struct SpaceshipMissionSimulator::Planet gravity=9.807, key=:earth, name="Earth">, reserved_fuel_weight=0, fuel_weight=13447>]>>>
|
38
|
+
|
39
|
+
scc.print_spaceship_mission_result 28_801, raw_path
|
40
|
+
|
41
|
+
# =>
|
42
|
+
|
43
|
+
[
|
44
|
+
[0] "path: launch Earth, land Moon, launch Moon, land Earth",
|
45
|
+
[1] "weight of equipment: 28801 kg",
|
46
|
+
[2] "weight of fuel: 51898 kg",
|
47
|
+
[3] "arguments: 28801, [[:launch, 9.807], [:land, 1.62], [:launch, 1.62], [:land, 9.807]]"
|
48
|
+
]
|
49
|
+
```
|
50
|
+
|
51
|
+
Or you can use rake task to print result:
|
52
|
+
|
53
|
+
$ rake spaceship_mission_simulator:print_result[28_801,'launch: 9.807; land: 1.62; launch: 1.62; land: 9.807']
|
54
|
+
|
55
|
+
```
|
56
|
+
# =>
|
57
|
+
|
58
|
+
[
|
59
|
+
[0] "path: launch Earth, land Moon, launch Moon, land Earth",
|
60
|
+
[1] "weight of equipment: 28801 kg",
|
61
|
+
[2] "weight of fuel: 51898 kg",
|
62
|
+
[3] "arguments: 28801, [[:launch, 9.807], [:land, 1.62], [:launch, 1.62], [:land, 9.807]]"
|
63
|
+
]
|
64
|
+
```
|
65
|
+
|
66
|
+
## Development
|
67
|
+
|
68
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/acidwizard/spaceship_mission_simulator.
|
73
|
+
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
desc 'Run tests'
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.libs << 'test'
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
t.warning = false
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :spaceship_mission_simulator do
|
12
|
+
require 'spaceship_mission_simulator'
|
13
|
+
|
14
|
+
include SpaceshipMissionSimulator
|
15
|
+
|
16
|
+
desc 'Print spaceship mission simulation result'
|
17
|
+
task :print_result, [:initial_weight, :raw_path] do |_t, args|
|
18
|
+
correct_raw_path = args.raw_path.split('; ').map do |ev_data|
|
19
|
+
ev_data.split(': ').tap do |ev_arr|
|
20
|
+
ev_arr[0] = ev_arr[0].to_sym
|
21
|
+
ev_arr[-1] = ev_arr[-1].to_f
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
print_spaceship_mission_result args.initial_weight.to_i, correct_raw_path
|
26
|
+
end
|
27
|
+
end
|
data/bin/setup
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'spaceship_mission_simulator/interactors/simulate'
|
2
|
+
|
3
|
+
module SpaceshipMissionSimulator
|
4
|
+
def simulate_spaceship_mission!(initial_weight, raw_path)
|
5
|
+
Simulate.call! initial_weight: initial_weight,
|
6
|
+
raw_path: raw_path
|
7
|
+
end
|
8
|
+
|
9
|
+
def print_spaceship_mission_result(*args)
|
10
|
+
simulate_spaceship_mission!(*args).result.awesome_print
|
11
|
+
rescue Interactor::Failure => e
|
12
|
+
p "Error: #{e.context.message}"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module SpaceshipMissionSimulator
|
2
|
+
EVENT_STATES = %i[land launch].freeze
|
3
|
+
EVENT_ATTRS = %i[state planet reserved_fuel_weight fuel_weight].freeze
|
4
|
+
|
5
|
+
Event = Struct.new(*EVENT_ATTRS, keyword_init: true) do
|
6
|
+
def self.known_state?(state)
|
7
|
+
EVENT_STATES.include? state
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'interactor'
|
2
|
+
require_relative '../planet'
|
3
|
+
|
4
|
+
module SpaceshipMissionSimulator
|
5
|
+
class IdentifyPlanet
|
6
|
+
include Interactor
|
7
|
+
|
8
|
+
before { permit_gravity_arg! }
|
9
|
+
|
10
|
+
def call
|
11
|
+
context.planet = Planet.new(gravity: context.gravity).fill_up_data
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def permit_gravity_arg!
|
17
|
+
return true if Planet.known_gravity?(context.gravity)
|
18
|
+
|
19
|
+
msg = "fail to identify planet with '#{context.gravity}' gravity"
|
20
|
+
context.fail! message: msg
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'interactor'
|
2
|
+
require_relative './validate_raw_path'
|
3
|
+
require_relative './validate_start_event'
|
4
|
+
require_relative './validate_finish_event'
|
5
|
+
require_relative './validate_path_consistency'
|
6
|
+
require_relative './simulate_event'
|
7
|
+
require_relative '../path'
|
8
|
+
require_relative '../simulation_result'
|
9
|
+
|
10
|
+
module SpaceshipMissionSimulator
|
11
|
+
class Simulate
|
12
|
+
include Interactor
|
13
|
+
|
14
|
+
before { ValidateRawPath.call! context }
|
15
|
+
|
16
|
+
def call
|
17
|
+
context.result = build_new_result
|
18
|
+
|
19
|
+
simulate_events_from_last_one do |prev_event|
|
20
|
+
add_path_event prev_event
|
21
|
+
validate_added_event!
|
22
|
+
sum_total_fuel_weight prev_event
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def validate_added_event!
|
29
|
+
path_ctx = { path: path }
|
30
|
+
ValidatePathConsistency.call! path_ctx
|
31
|
+
ValidateStartEvent.call! path_ctx if path.start_event?
|
32
|
+
ValidateFinishEvent.call! path_ctx if path.finish_event?
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_path_event(prev_event)
|
36
|
+
path.events.prepend prev_event
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_new_result
|
40
|
+
new_path = Path.new raw_data: pull_from_context(:raw_path), events: []
|
41
|
+
SimulationResult.new path: new_path,
|
42
|
+
total_fuel_weight: 0,
|
43
|
+
initial_weight: pull_from_context(:initial_weight)
|
44
|
+
end
|
45
|
+
|
46
|
+
def path
|
47
|
+
context.result.path
|
48
|
+
end
|
49
|
+
|
50
|
+
def pull_from_context(key)
|
51
|
+
context.send(key).tap { context.delete_field key }
|
52
|
+
end
|
53
|
+
|
54
|
+
def simulate_event(raw_event_data, reserved_fuel_weight)
|
55
|
+
SimulateEvent.call!(initial_weight: context.result.initial_weight,
|
56
|
+
raw_data: raw_event_data,
|
57
|
+
reserved_fuel_weight: reserved_fuel_weight).event
|
58
|
+
end
|
59
|
+
|
60
|
+
def simulate_events_from_last_one
|
61
|
+
path.raw_data.reverse.inject(0) do |reserved_fuel_weight, raw_event_data|
|
62
|
+
event = simulate_event raw_event_data, reserved_fuel_weight
|
63
|
+
yield event
|
64
|
+
reserved_fuel_weight + event.fuel_weight
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def sum_total_fuel_weight(event)
|
69
|
+
context.result.total_fuel_weight += event.fuel_weight
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'interactor'
|
2
|
+
|
3
|
+
require_relative './validate_initial_weight'
|
4
|
+
require_relative './validate_event_data'
|
5
|
+
require_relative './validate_event_state'
|
6
|
+
require_relative './identify_planet'
|
7
|
+
require_relative '../event'
|
8
|
+
|
9
|
+
module SpaceshipMissionSimulator
|
10
|
+
class SimulateEvent
|
11
|
+
include Interactor
|
12
|
+
|
13
|
+
before do
|
14
|
+
context.reserved_fuel_weight ||= 0
|
15
|
+
|
16
|
+
ValidateInitialWeight.call! context
|
17
|
+
ValidateEventData.call! context
|
18
|
+
ValidateEventState.call! context
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
context.event = build_event
|
23
|
+
context.event.planet = identify_planet
|
24
|
+
context.event.fuel_weight = calc_fuel
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def build_event
|
30
|
+
Event.new state: context.raw_data.first.to_sym,
|
31
|
+
reserved_fuel_weight: context.reserved_fuel_weight
|
32
|
+
end
|
33
|
+
|
34
|
+
def calc_fuel(mass = total_weight)
|
35
|
+
fuel = calc_fuel_by_event_formula mass, context.event.planet.gravity
|
36
|
+
|
37
|
+
return 0 unless fuel.positive?
|
38
|
+
|
39
|
+
calc_fuel(fuel) + fuel
|
40
|
+
end
|
41
|
+
|
42
|
+
def calc_fuel_by_event_formula(mass, gravity)
|
43
|
+
if context.event.state == :land
|
44
|
+
(mass * gravity * 0.033 - 42).to_i
|
45
|
+
elsif context.event.state == :launch
|
46
|
+
(mass * gravity * 0.042 - 33).to_i
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def identify_planet
|
51
|
+
IdentifyPlanet.call!(gravity: context.raw_data.last).planet
|
52
|
+
end
|
53
|
+
|
54
|
+
def total_weight
|
55
|
+
context.initial_weight + context.reserved_fuel_weight
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SpaceshipMissionSimulator
|
2
|
+
class ValidateEventData
|
3
|
+
include Interactor
|
4
|
+
|
5
|
+
def call
|
6
|
+
return true if correct_event_data?
|
7
|
+
|
8
|
+
msg = 'should provide proper event format ([state, gravity])'
|
9
|
+
context.fail! message: msg
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def correct_event_data?
|
15
|
+
context.raw_data.is_a?(Array) && context.raw_data.size == 2
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SpaceshipMissionSimulator
|
2
|
+
class ValidateEventState
|
3
|
+
include Interactor
|
4
|
+
|
5
|
+
def call
|
6
|
+
event_state = context.raw_data.first.to_sym
|
7
|
+
|
8
|
+
return true if Event.known_state?(event_state)
|
9
|
+
|
10
|
+
context.fail! message: 'should be only land or launch'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SpaceshipMissionSimulator
|
2
|
+
class ValidateFinishEvent
|
3
|
+
include Interactor
|
4
|
+
|
5
|
+
def call
|
6
|
+
event = context.path.events.last
|
7
|
+
|
8
|
+
return true if event.planet.key == :earth && event.state == :land
|
9
|
+
|
10
|
+
msg = 'spaceship mission should finish only by land on Earth'
|
11
|
+
context.fail! message: msg
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module SpaceshipMissionSimulator
|
2
|
+
class ValidatePathConsistency
|
3
|
+
include Interactor
|
4
|
+
|
5
|
+
def call
|
6
|
+
return true if context.path.fresh_event_consistent?
|
7
|
+
|
8
|
+
msg = 'spaceship mission path should be consistent (launch -> land)'
|
9
|
+
context.fail! message: msg
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SpaceshipMissionSimulator
|
2
|
+
class ValidateStartEvent
|
3
|
+
include Interactor
|
4
|
+
|
5
|
+
def call
|
6
|
+
event = context.path.events.first
|
7
|
+
|
8
|
+
return true if event.planet.key == :earth && event.state == :launch
|
9
|
+
|
10
|
+
msg = 'spaceship mission should start only by launch from Earth'
|
11
|
+
context.fail! message: msg
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SpaceshipMissionSimulator
|
2
|
+
Path = Struct.new(:raw_data, :events, keyword_init: true) do
|
3
|
+
def fresh_event_consistent?
|
4
|
+
finish_event? || events[0].state != events[1].state
|
5
|
+
end
|
6
|
+
|
7
|
+
def finish_event?
|
8
|
+
events.size == 1
|
9
|
+
end
|
10
|
+
|
11
|
+
def start_event?
|
12
|
+
events.size == raw_data.size
|
13
|
+
end
|
14
|
+
|
15
|
+
def print
|
16
|
+
events.map { |event| "#{event.state} #{event.planet.name}" }.join ', '
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SpaceshipMissionSimulator
|
2
|
+
AVAILABLE_PLANETS = {
|
3
|
+
earth: 9.807, moon: 1.62, mars: 3.711
|
4
|
+
}.freeze
|
5
|
+
|
6
|
+
Planet = Struct.new(:gravity, :key, :name, keyword_init: true) do
|
7
|
+
def self.known_gravity?(gravity)
|
8
|
+
AVAILABLE_PLANETS.value? gravity
|
9
|
+
end
|
10
|
+
|
11
|
+
def fill_up_data
|
12
|
+
tap do |planet|
|
13
|
+
planet.key = AVAILABLE_PLANETS.key gravity
|
14
|
+
planet.name = key.to_s.capitalize
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'awesome_print'
|
2
|
+
|
3
|
+
module SpaceshipMissionSimulator
|
4
|
+
RESULT_ATTRS = %i[initial_weight total_fuel_weight path].freeze
|
5
|
+
|
6
|
+
SimulationResult = Struct.new(*RESULT_ATTRS, keyword_init: true) do
|
7
|
+
def awesome_print
|
8
|
+
with_suppressed_warnings do
|
9
|
+
ap ["path: #{path.print}",
|
10
|
+
"weight of equipment: #{initial_weight} kg",
|
11
|
+
"weight of fuel: #{total_fuel_weight} kg",
|
12
|
+
"arguments: #{initial_weight}, #{path.raw_data}"]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def with_suppressed_warnings
|
19
|
+
original_verbose = $VERBOSE
|
20
|
+
$VERBOSE = nil
|
21
|
+
yield
|
22
|
+
$VERBOSE = original_verbose
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/spaceship_mission_simulator/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'spaceship_mission_simulator'
|
5
|
+
spec.version = SpaceshipMissionSimulator::VERSION
|
6
|
+
spec.authors = ['acidwizard']
|
7
|
+
|
8
|
+
spec.summary = 'The goal of this gem is to calculate fuel to launch from one planet of the Solar System, and land to another planet of the Solar System, depending on the flight route.'
|
9
|
+
spec.homepage = 'https://github.com/acidwizard/spaceship_mission_simulator'
|
10
|
+
spec.license = 'MIT'
|
11
|
+
|
12
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
13
|
+
spec.metadata['source_code_uri'] = 'https://github.com/acidwizard/spaceship_mission_simulator'
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.required_ruby_version = Gem::Requirement.new '>= 2.3.0'
|
24
|
+
|
25
|
+
spec.add_dependency 'awesome_print', '1.8.0'
|
26
|
+
spec.add_dependency 'interactor', '3.1.2'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
29
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 0.8'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spaceship_mission_simulator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- acidwizard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: awesome_print
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: interactor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.1.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.1.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- ".rubocop.yml"
|
91
|
+
- ".ruby-gemset"
|
92
|
+
- ".ruby-version"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/setup
|
100
|
+
- lib/spaceship_mission_simulator.rb
|
101
|
+
- lib/spaceship_mission_simulator/event.rb
|
102
|
+
- lib/spaceship_mission_simulator/interactors/identify_planet.rb
|
103
|
+
- lib/spaceship_mission_simulator/interactors/simulate.rb
|
104
|
+
- lib/spaceship_mission_simulator/interactors/simulate_event.rb
|
105
|
+
- lib/spaceship_mission_simulator/interactors/validate_event_data.rb
|
106
|
+
- lib/spaceship_mission_simulator/interactors/validate_event_state.rb
|
107
|
+
- lib/spaceship_mission_simulator/interactors/validate_finish_event.rb
|
108
|
+
- lib/spaceship_mission_simulator/interactors/validate_initial_weight.rb
|
109
|
+
- lib/spaceship_mission_simulator/interactors/validate_path_consistency.rb
|
110
|
+
- lib/spaceship_mission_simulator/interactors/validate_raw_path.rb
|
111
|
+
- lib/spaceship_mission_simulator/interactors/validate_start_event.rb
|
112
|
+
- lib/spaceship_mission_simulator/path.rb
|
113
|
+
- lib/spaceship_mission_simulator/planet.rb
|
114
|
+
- lib/spaceship_mission_simulator/simulation_result.rb
|
115
|
+
- lib/spaceship_mission_simulator/version.rb
|
116
|
+
- spaceship_mission_simulator.gemspec
|
117
|
+
homepage: https://github.com/acidwizard/spaceship_mission_simulator
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata:
|
121
|
+
homepage_uri: https://github.com/acidwizard/spaceship_mission_simulator
|
122
|
+
source_code_uri: https://github.com/acidwizard/spaceship_mission_simulator
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.3.0
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.1.2
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: The goal of this gem is to calculate fuel to launch from one planet of the
|
142
|
+
Solar System, and land to another planet of the Solar System, depending on the flight
|
143
|
+
route.
|
144
|
+
test_files: []
|