module Olib
TODO: this should be refactored to use a mixin pattern
Constants
- VERSION
Public Class Methods
CLI()
click to toggle source
# File lib/Olib/utils/cli.rb, line 78 def Olib.CLI Olib::ScriptVars.new end
Go2()
click to toggle source
# File lib/Olib/go2.rb, line 128 def Olib.Go2 Olib::Go2 end
Playershop()
click to toggle source
# File lib/Olib/shops.rb, line 170 def Olib.Playershop Olib::Shop::Playershop end
Shop()
click to toggle source
# File lib/Olib/shops.rb, line 174 def Olib.Shop Olib::Shop end
debug(msg)
click to toggle source
# File lib/Olib/core/utils.rb, line 83 def Olib.debug(msg) return unless @@debug echo "Olib.debug> #{msg}" end
do(action, re)
click to toggle source
invoke update notifier immediately Olib.update_notifier
# File lib/Olib.rb, line 71 def Olib.do(action, re) dothistimeout action, 5, re end
exit()
click to toggle source
# File lib/Olib/core/utils.rb, line 190 def Olib.exit raise Olib::Errors::Mundane end
methodize(str)
click to toggle source
# File lib/Olib.rb, line 54 def Olib.methodize(str) str.to_s.downcase.strip.gsub(/-|\s+|'|"/, "_").to_sym end
monsterbold(str)
click to toggle source
# File lib/Olib/utils/monsterbold.rb, line 2 def Olib.monsterbold(str) "<pushBold/>#{str}<popBold/>" end
run(script, *args)
click to toggle source
# File lib/Olib.rb, line 75 def Olib.run(script, *args) start_script script, args wait_while { running? script } end
script()
click to toggle source
# File lib/Olib/core/utils.rb, line 120 def Olib.script Script.current end
timeout(sec) { |sec| ... }
click to toggle source
# File lib/Olib/core/utils.rb, line 88 def Olib.timeout(sec) #:yield: +sec+ return yield(sec) if sec == nil or sec.zero? begin current_thread = Thread.current x = Thread.start{ begin yield(sec) rescue => e current_thread.raise e end } y = Thread.start { begin sleep sec rescue => e x.raise e else x.kill current_thread.raise Olib::Errors::TimedOut end } x.value ensure if y y.kill y.join # make sure y is dead. end end end
toggle_debug()
click to toggle source
# File lib/Olib/core/utils.rb, line 79 def Olib.toggle_debug @@debug = @@debug ? false : true end
turn_off_xml()
click to toggle source
# File lib/Olib/core/utils.rb, line 132 def Olib.turn_off_xml if @@xml @@xml = false Script.current.want_downstream_xml = @@xml end self end
turn_on_xml()
click to toggle source
# File lib/Olib/core/utils.rb, line 124 def Olib.turn_on_xml if not @@xml @@xml = true Script.current.want_downstream_xml = @@xml end self end
update_notifier()
click to toggle source
# File lib/Olib.rb, line 41 def Olib.update_notifier begin response = JSON.parse Net::HTTP.get URI('https://rubygems.org/api/v1/gems/Olib.json') # check version if Gem.loaded_specs["Olib"].version < Gem::Version.new(response['version']) puts "<pushBold/>You need to update the Olib gem with a `gem install Olib`<popBold/>" end rescue echo $! puts $!.backtrace[0..1] end end
vars()
click to toggle source
# File lib/Olib/core/utils.rb, line 74 def Olib.vars ScriptVars.new end
wrap(action = nil) { |line| ... }
click to toggle source
# File lib/Olib/core/utils.rb, line 144 def Olib.wrap(action = nil) begin Olib.timeout(3) { put action if action while (line=get) next if Dictionary.ignorable?(line) # attempt at removing PC action that turned out to be more harmful than good # next if not GameObj.pcs.nil? and line =~ /#{GameObj.pcs.join('|')}/ yield line end } rescue Olib::Errors::TimedOut Olib.debug "timeout... " # Silent rescue Olib::Errors::Mundane => e rescue Olib::Errors::Prempt => e end end
wrap_greedy(action) { |line| ... }
click to toggle source
# File lib/Olib/core/utils.rb, line 168 def Olib.wrap_greedy(action) begin Olib.timeout(3) { put action while (line=get) #next if not GameObj.pcs.nil? and line =~ /#{GameObj.pcs.join('|')}/ yield line end } rescue Olib::Errors::TimedOut Olib.debug "timeout... " # Silent rescue Olib::Errors::Mundane => e rescue Olib::Errors::Prempt => e end end
wrap_stream(action = nil) { |line| ... }
click to toggle source
# File lib/Olib/core/utils.rb, line 194 def Olib.wrap_stream(action = nil) begin Olib.turn_on_xml Olib.timeout(3) { if action then fput action end while (line=get) next if Olib::Dictionary.ignorable?(line) # next if not GameObj.pcs.nil? and line =~ /#{GameObj.pcs.join('|')}/ yield line end } rescue Olib::Errors::TimedOut Olib.debug "timeout... " # Silent rescue Olib::Errors::Mundane => e Olib.debug "mundane..." rescue Olib::Errors::Prempt => e Olib.debug "waiting prempted..." ensure Olib.turn_off_xml end end
xml?()
click to toggle source
# File lib/Olib/core/utils.rb, line 140 def Olib.xml? @@xml end