class TFClient::Models::Structures
Public Class Methods
new(lines:)
click to toggle source
Calls superclass method
TFClient::Models::Model::new
# File lib/textflight-client/models/nav.rb, line 256 def initialize(lines:) line, index = ResponseParser.line_and_index_for_beginning_with(lines: lines, string: "Structures") super(line: line) items = ResponseParser.collect_list_items(lines: lines, start_index: index + 1) @items = items.map do |item| line = item.strip hash = ResponseParser.hash_from_line_values(line: line) id = hash[:id].to_i name = hash[:name] # TODO: distinguish shipyards from bases type = hash[:sclass] || "base" { id: id, name: name, type: type } end end
Public Instance Methods
to_s()
click to toggle source
# File lib/textflight-client/models/nav.rb, line 275 def to_s table = TTY::Table.new(header: [ {value: "#{@translation}", alignment: :right}, {value: "name", alignment: :center}, {value: "ship class", alignment: :center}, {value: "id", alignment: :center } ]) @items.each do |item| table << ["[#{item[:id]}]", item[:name], item[:type], "[#{item[:id]}]"] end table.render(:ascii, Models::TABLE_OPTIONS) do |renderer| renderer.alignments= [:right, :right, :center, :center] end end