class TFClient::Models::Cargo
Public Class Methods
new(lines:)
click to toggle source
Calls superclass method
TFClient::Models::Model::new
# File lib/textflight-client/models/scan.rb, line 171 def initialize(lines:) line, index = ResponseParser.line_and_index_for_beginning_with(lines: lines, string: "Cargo") 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) index = hash[:index].to_i name = hash[:name] count = hash[:count].to_i # TODO: this must be the mark? mark = hash[:extra].to_i { index: index, name: name, count: count, mark: mark} end end
Public Instance Methods
to_s()
click to toggle source
# File lib/textflight-client/models/scan.rb, line 191 def to_s table = TTY::Table.new(header: [ "Weight: #{weight}", {value: "cargo", alignment: :center}, {value: "amount", alignment: :center}, {value: "index", alignment: :center} ]) @items.each do |item| name = item[:name] mark = item[:mark].to_i if mark && (mark != 0) name = "#{name} (#{mark.to_roman})" end table << ["[#{item[:index]}]", name, item[:count], "[#{item[:index]}]"] end table.render(:ascii, Models::TABLE_OPTIONS) do |renderer| renderer.alignments= [:right, :right, :center, :center] end end
weight()
click to toggle source
TODO: only some items in the inventory contribute to weight
# File lib/textflight-client/models/scan.rb, line 217 def weight @items.map { |hash| hash[:count] }.sum end