Class: Arkrb::OutputParsing
- Inherits:
-
Object
- Object
- Arkrb::OutputParsing
- Defined in:
- lib/arkrb/output_parsing.rb
Instance Method Summary collapse
- #backup(output) ⇒ True, Exception
- #broadcast(output) ⇒ True, Exception
- #check_update(output) ⇒ Object
- #disable_mod(output) ⇒ True, Exception
- #enable_mod(output) ⇒ True, Exception
- #install(output) ⇒ Object
- #install_mod(output) ⇒ True, Exception
- #rconcmd(output) ⇒ Object
- #reinstall_mod(output) ⇒ True, Exception
- #restart(output) ⇒ True, Exception
- #sanitize!(command, output) ⇒ Object
- #save_world(output) ⇒ True, Exception
- #start(output) ⇒ True, Exception
- #status(output) ⇒ Object
- #stop(output) ⇒ True, Exception
- #uninstall_mod(output) ⇒ True, Exception
- #update(output) ⇒ True, Exception
Instance Method Details
#backup(output) ⇒ True, Exception
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/arkrb/output_parsing.rb', line 97 def backup(output) if output =~ /Created Backup/im console_response = output.split("\n").map {|x| x.gsub(/\e\[([;\d]+)?m/, '').strip} dir_path = console_response.find {|x| x =~ /Saved arks directory is/im}.split('directory is').last.strip file_name = console_response.find {|x| x =~ /Created Backup/im}.split(':').last.strip { status: 'success', path: File.join(dir_path, file_name) } else raise_unknown_error(__method__.to_sym, output) end end |
#broadcast(output) ⇒ True, Exception
166 167 168 169 170 171 172 |
# File 'lib/arkrb/output_parsing.rb', line 166 def broadcast(output) if output =~ /command processed/im true else raise_unknown_error(__method__.to_sym, output.gsub("\r", "\n")) end end |
#check_update(output) ⇒ Object
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/arkrb/output_parsing.rb', line 179 def check_update(output) outputs = output.gsub(/\e\[([;\d]+)?m/, '').strip.split("\n") current_version = outputs.find {|x| x =~ /Current version/im }.split(':').last.strip available_version = outputs.find {|x| x =~ /Available version/im }.split(':').last.strip { current: current_version, available: available_version, update_available: current_version != available_version } end |
#disable_mod(output) ⇒ True, Exception
130 131 132 133 134 135 136 |
# File 'lib/arkrb/output_parsing.rb', line 130 def disable_mod(output) if output =~ /disablemod/im true else raise_unknown_error(__method__.to_sym, output) end end |
#enable_mod(output) ⇒ True, Exception
121 122 123 124 125 126 127 |
# File 'lib/arkrb/output_parsing.rb', line 121 def enable_mod(output) if output =~ /enable mod/im true else raise_unknown_error(__method__.to_sym, output) end end |
#install(output) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/arkrb/output_parsing.rb', line 13 def install(output) if output.strip.empty? true else if output =~ /#{'server already running'}/im raise Arkrb::Error::ServerAlreadyRunning, output else raise_unknown_error(:install, output) end end end |
#install_mod(output) ⇒ True, Exception
139 140 141 142 143 144 145 |
# File 'lib/arkrb/output_parsing.rb', line 139 def install_mod(output) if output =~ /mod [0-9]+ installed/im true else raise_unknown_error(__method__.to_sym, output.gsub("\r", "\n")) end end |
#rconcmd(output) ⇒ Object
175 176 177 |
# File 'lib/arkrb/output_parsing.rb', line 175 def rconcmd(output) output end |
#reinstall_mod(output) ⇒ True, Exception
157 158 159 160 161 162 163 |
# File 'lib/arkrb/output_parsing.rb', line 157 def reinstall_mod(output) if output =~ /mod [0-9]+ installed/im true else raise_unknown_error(__method__.to_sym, output.gsub("\r", "\n")) end end |
#restart(output) ⇒ True, Exception
52 53 54 55 56 57 58 |
# File 'lib/arkrb/output_parsing.rb', line 52 def restart(output) if output =~ /#{'the server is now running'}/im true else raise_unknown_error(__method__.to_sym, output) end end |
#sanitize!(command, output) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/arkrb/output_parsing.rb', line 4 def sanitize!(command, output) if public_methods(false).include?(command.to_sym) method(command.to_sym).call(output) else raise Arkrb::Error::SanitizationUnsupportedForThisMethod, "\n#{output}" end end |
#save_world(output) ⇒ True, Exception
112 113 114 115 116 117 118 |
# File 'lib/arkrb/output_parsing.rb', line 112 def save_world(output) if output =~ /world saved/im true else raise_unknown_error(__method__.to_sym, output) end end |
#start(output) ⇒ True, Exception
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/arkrb/output_parsing.rb', line 26 def start(output) if output =~ /#{'the server is now running'}/im true else if output =~ /#{'server already running'}/im raise Arkrb::Error::ServerAlreadyRunning, output else raise_unknown_error(:start, output) end end end |
#status(output) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/arkrb/output_parsing.rb', line 60 def status(output) status_items = {} defaults = { running: nil, pid: nil, listening: nil, name: nil, players: nil, active_players: nil, online: nil, arkservers_link: nil, build_id: nil, version: nil } status = output.gsub(/\e\[([;\d]+)?m/, '') if status =~ /Server running/im status = status.split("\n").map {|s| s.strip} status.shift status.each do |item| item_info = item.split(':', 2) status_items[item_info.first.gsub('Server ', '').strip.downcase.tr(' ', '_').to_sym] = item_info[1].strip end status_items[:running] = (status_items.fetch(:running, 'no') =~ /yes/im) ? true : false status_items[:listening] = (status_items.fetch(:listening, 'no') =~ /yes/im) ? true : false status_items[:online] = (status_items.fetch(:online, 'no') =~ /yes/im) ? true : false defaults.merge(status_items) else raise_unknown_error(__method__.to_sym, output) end end |
#stop(output) ⇒ True, Exception
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/arkrb/output_parsing.rb', line 39 def stop(output) if output =~ /#{'The server has been stopped'}/im true else if output =~ /#{'The server is already stopped'}/im raise Arkrb::Error::ServerAlreadyStopped, output else raise_unknown_error(__method__.to_sym, output) end end end |
#uninstall_mod(output) ⇒ True, Exception
148 149 150 151 152 153 154 |
# File 'lib/arkrb/output_parsing.rb', line 148 def uninstall_mod(output) if output =~ /uninstallmod/im true else raise_unknown_error(__method__.to_sym, output) end end |
#update(output) ⇒ True, Exception
86 87 88 89 90 91 92 93 |
# File 'lib/arkrb/output_parsing.rb', line 86 def update(output) if output =~ /#{'already up to date'}/im || output =~ /#{'updated'}/im # output true else raise_unknown_error(__method__.to_sym, output) end end |