class TFClient::Models::Scan
Constants
- LINE_IDENTIFIERS
Attributes
cargo[R]
id[R]
name[R]
outfit_space[R]
outfits[R]
owner[R]
shield_charge[R]
Public Class Methods
new(lines:)
click to toggle source
Calls superclass method
TFClient::Models::Response::new
# File lib/textflight-client/models/scan.rb, line 18 def initialize(lines:) super(lines: lines) ship_line = lines[0] values_hash = ResponseParser.hash_from_line_values(line: ship_line) @id = values_hash[:id].to_i @name = values_hash[:name] LINE_IDENTIFIERS.each do |line_id| # Not sure what value this adds next if line_id == "Operators" var_name = ResponseParser.snake_case_sym_from_string(string: line_id) class_name = ResponseParser.camel_case_from_string(string: line_id) clazz = ResponseParser.model_class_from_string(string: class_name) if clazz.nil? raise "could not find class name: #{class_name} derived from #{line_id}" end line, _ = ResponseParser.line_and_index_for_beginning_with(lines: @lines, string: line_id) if ["Owner", "Outfit space", "Shield charge"].include?(line_id) var = clazz.new(line: line) elsif ["Outfits", "Cargo"].include?(line_id) var = clazz.new(lines: @lines) if var.is_a?(TFClient::Models::Outfits) var.max_slots = @outfit_space.value end else raise "Cannot find class initializer for: #{line_id}" end instance_variable_set("@#{var_name}", var) end end
Public Instance Methods
response()
click to toggle source
# File lib/textflight-client/models/scan.rb, line 57 def response # TODO this is interesting only when you scan _other_ structures # table = TTY::Table.new(header: [ # {value: @owner.translation, alignment: :center}, # {value: @outfit_space.translation, alignment: :center}, # {value: @shield_charge.translation, alignment: :center} # ]) # # table << [@owner.username, # @outfit_space.value, # @shield_charge.value] # # puts table.render(:ascii, padding: [0,1,0,1], # width: Models::TABLE_WIDTH, resize: true) do |renderer| # renderer.alignments= [:center, :center, :center] # end puts @outfits.to_s puts @cargo.to_s end