class TFClient::Models::Outfits
Attributes
max_slots[RW]
Public Class Methods
new(lines:)
click to toggle source
Calls superclass method
TFClient::Models::Model::new
# File lib/textflight-client/models/scan.rb, line 122 def initialize(lines:) line, index = ResponseParser.line_and_index_for_beginning_with(lines: lines, string: "Outfits") 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] mark = hash[:mark].to_i setting = hash[:setting].to_i { index: index, name: name, mark: mark, setting: setting} end @max_slots = 0 end
Public Instance Methods
slots_used()
click to toggle source
# File lib/textflight-client/models/scan.rb, line 164 def slots_used @items.map { |hash| hash[:mark] }.sum end
to_s()
click to toggle source
# File lib/textflight-client/models/scan.rb, line 142 def to_s table = TTY::Table.new(header: [ "#{@translation}: #{slots_used}/#{@max_slots} slots", {value: "name", alignment: :center}, {value: "setting", alignment: :center}, {value: "index", alignment: :center} ]) @items.each do |item| table << [ "[#{item[:index]}]", "#{item[:name]} (#{item[:mark].to_roman})", item[:setting], "[#{item[:index]}]" ] end table.render(:ascii, Models::TABLE_OPTIONS) do |renderer| renderer.alignments= [:right, :right, :center, :center] end end