Class: TFClient::Models::Scan
- Defined in:
- lib/textflight-client/models/scan.rb
Constant Summary collapse
- LINE_IDENTIFIERS =
[ "Owner", "Operators", "Outfit space", "Shield charge", "Outfits", "Cargo" ]
Instance Attribute Summary collapse
-
#cargo ⇒ Object
readonly
Returns the value of attribute cargo.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#outfit_space ⇒ Object
readonly
Returns the value of attribute outfit_space.
-
#outfits ⇒ Object
readonly
Returns the value of attribute outfits.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#shield_charge ⇒ Object
readonly
Returns the value of attribute shield_charge.
Attributes inherited from Response
Instance Method Summary collapse
-
#initialize(lines:) ⇒ Scan
constructor
A new instance of Scan.
- #response ⇒ Object
Constructor Details
#initialize(lines:) ⇒ Scan
Returns a new instance of Scan.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |
Instance Attribute Details
#cargo ⇒ Object (readonly)
Returns the value of attribute cargo.
16 17 18 |
# File 'lib/textflight-client/models/scan.rb', line 16 def cargo @cargo end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/textflight-client/models/scan.rb', line 15 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/textflight-client/models/scan.rb', line 15 def name @name end |
#outfit_space ⇒ Object (readonly)
Returns the value of attribute outfit_space.
15 16 17 |
# File 'lib/textflight-client/models/scan.rb', line 15 def outfit_space @outfit_space end |
#outfits ⇒ Object (readonly)
Returns the value of attribute outfits.
16 17 18 |
# File 'lib/textflight-client/models/scan.rb', line 16 def outfits @outfits end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
15 16 17 |
# File 'lib/textflight-client/models/scan.rb', line 15 def owner @owner end |
#shield_charge ⇒ Object (readonly)
Returns the value of attribute shield_charge.
15 16 17 |
# File 'lib/textflight-client/models/scan.rb', line 15 def shield_charge @shield_charge end |
Instance Method Details
#response ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# 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 |