Class: TFClient::Models::Outfits
- Inherits:
-
ModelWithItems
- Object
- Model
- ModelWithItems
- TFClient::Models::Outfits
- Defined in:
- lib/textflight-client/models/scan.rb
Instance Attribute Summary collapse
-
#max_slots ⇒ Object
Returns the value of attribute max_slots.
Attributes inherited from ModelWithItems
Attributes inherited from Model
#label, #translation, #values_hash
Instance Method Summary collapse
-
#initialize(lines:) ⇒ Outfits
constructor
A new instance of Outfits.
- #slots_used ⇒ Object
- #to_s ⇒ Object
Methods inherited from ModelWithItems
#count, #items_to_s, #lines_offset, #response_str
Constructor Details
#initialize(lines:) ⇒ Outfits
Returns a new instance of Outfits.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# 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 |
Instance Attribute Details
#max_slots ⇒ Object
Returns the value of attribute max_slots.
120 121 122 |
# File 'lib/textflight-client/models/scan.rb', line 120 def max_slots @max_slots end |
Instance Method Details
#slots_used ⇒ Object
164 165 166 |
# File 'lib/textflight-client/models/scan.rb', line 164 def slots_used @items.map { |hash| hash[:mark] }.sum end |
#to_s ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# 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 |