Class: MinerMover::Run
- Inherits:
-
Object
- Object
- MinerMover::Run
- Defined in:
- lib/miner_mover/run.rb
Instance Attribute Summary collapse
-
#cfg ⇒ Object
Returns the value of attribute cfg.
-
#cfg_file ⇒ Object
Returns the value of attribute cfg_file.
-
#debugging ⇒ Object
Returns the value of attribute debugging.
-
#logging ⇒ Object
Returns the value of attribute logging.
-
#miner ⇒ Object
Returns the value of attribute miner.
-
#mover ⇒ Object
Returns the value of attribute mover.
-
#num_miners ⇒ Object
Returns the value of attribute num_miners.
-
#num_movers ⇒ Object
Returns the value of attribute num_movers.
-
#ore_limit ⇒ Object
Returns the value of attribute ore_limit.
-
#time_limit ⇒ Object
Returns the value of attribute time_limit.
-
#timer ⇒ Object
Returns the value of attribute timer.
Class Method Summary collapse
Instance Method Summary collapse
- #cfg_banner!(duration: 0) ⇒ Object
- #debug(msg) ⇒ Object
-
#initialize(cfg_file: nil, timer: nil) ⇒ Run
constructor
A new instance of Run.
- #log(msg) ⇒ Object
- #new_miner ⇒ Object
- #new_mover ⇒ Object
- #ore_limit?(ore_mined) ⇒ Boolean
- #start! ⇒ Object
- #time_limit? ⇒ Boolean
- #timestamp! ⇒ Object
Constructor Details
#initialize(cfg_file: nil, timer: nil) ⇒ Run
Returns a new instance of Run.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/miner_mover/run.rb', line 24 def initialize(cfg_file: nil, timer: nil) @cfg_file = self.class.cfg_file(cfg_file) @cfg = Config.process @cfg_file main = @cfg.fetch :main @miner = @cfg.fetch :miner @mover = @cfg.fetch :mover @num_miners = main.fetch :num_miners @num_movers = main.fetch :num_movers @time_limit = main.fetch :time_limit @ore_limit = main.fetch :ore_limit @logging = main.fetch :logging @debugging = main.fetch :debugging @timer = timer || Timer.new end |
Instance Attribute Details
#cfg ⇒ Object
Returns the value of attribute cfg.
21 22 23 |
# File 'lib/miner_mover/run.rb', line 21 def cfg @cfg end |
#cfg_file ⇒ Object
Returns the value of attribute cfg_file.
21 22 23 |
# File 'lib/miner_mover/run.rb', line 21 def cfg_file @cfg_file end |
#debugging ⇒ Object
Returns the value of attribute debugging.
19 20 21 |
# File 'lib/miner_mover/run.rb', line 19 def debugging @debugging end |
#logging ⇒ Object
Returns the value of attribute logging.
19 20 21 |
# File 'lib/miner_mover/run.rb', line 19 def logging @logging end |
#miner ⇒ Object
Returns the value of attribute miner.
21 22 23 |
# File 'lib/miner_mover/run.rb', line 21 def miner @miner end |
#mover ⇒ Object
Returns the value of attribute mover.
21 22 23 |
# File 'lib/miner_mover/run.rb', line 21 def mover @mover end |
#num_miners ⇒ Object
Returns the value of attribute num_miners.
20 21 22 |
# File 'lib/miner_mover/run.rb', line 20 def num_miners @num_miners end |
#num_movers ⇒ Object
Returns the value of attribute num_movers.
20 21 22 |
# File 'lib/miner_mover/run.rb', line 20 def num_movers @num_movers end |
#ore_limit ⇒ Object
Returns the value of attribute ore_limit.
22 23 24 |
# File 'lib/miner_mover/run.rb', line 22 def ore_limit @ore_limit end |
#time_limit ⇒ Object
Returns the value of attribute time_limit.
22 23 24 |
# File 'lib/miner_mover/run.rb', line 22 def time_limit @time_limit end |
#timer ⇒ Object
Returns the value of attribute timer.
21 22 23 |
# File 'lib/miner_mover/run.rb', line 21 def timer @timer end |
Class Method Details
.cfg_file(filename = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/miner_mover/run.rb', line 7 def self.cfg_file(filename = nil) f = filename || ARGV.shift || Config.recent if f.nil? raise(Config::Error, "no config file") elsif !File.exist? f raise(Config::Error, "can't find file #{f.inspect}") elsif !File.readable? f raise(Config::Error, "can't read file #{f.inspect}") end f end |
Instance Method Details
#cfg_banner!(duration: 0) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/miner_mover/run.rb', line 42 def (duration: 0) MinerMover.puts "USING: #{@cfg_file}" pp @cfg sleep duration if duration > 0 self end |
#debug(msg) ⇒ Object
80 81 82 |
# File 'lib/miner_mover/run.rb', line 80 def debug msg @debugging and MinerMover.log @timer, '(debug) ', msg end |
#log(msg) ⇒ Object
76 77 78 |
# File 'lib/miner_mover/run.rb', line 76 def log msg @logging and MinerMover.log @timer, ' (main) ', msg end |
#new_miner ⇒ Object
60 61 62 |
# File 'lib/miner_mover/run.rb', line 60 def new_miner Miner.new(**@miner) end |
#new_mover ⇒ Object
64 65 66 |
# File 'lib/miner_mover/run.rb', line 64 def new_mover Mover.new(**@mover) end |
#ore_limit?(ore_mined) ⇒ Boolean
68 69 70 |
# File 'lib/miner_mover/run.rb', line 68 def ore_limit?(ore_mined) Ore.block(ore_mined) > @ore_limit end |
#start! ⇒ Object
49 50 51 52 |
# File 'lib/miner_mover/run.rb', line 49 def start! @timer.restart self end |
#time_limit? ⇒ Boolean
72 73 74 |
# File 'lib/miner_mover/run.rb', line 72 def time_limit? @timer.elapsed > @time_limit end |
#timestamp! ⇒ Object
54 55 56 57 58 |
# File 'lib/miner_mover/run.rb', line 54 def dash = '-' * 70 str = [dash, Timer., dash].join(MinerMover::LINE_SEP) MinerMover.puts str end |