Class: TFClient::Models::Links
- Inherits:
-
ModelWithItems
- Object
- Model
- ModelWithItems
- TFClient::Models::Links
- Defined in:
- lib/textflight-client/models/nav.rb
Instance Attribute Summary
Attributes inherited from ModelWithItems
Attributes inherited from Model
#label, #translation, #values_hash
Instance Method Summary collapse
-
#initialize(lines:) ⇒ Links
constructor
A new instance of Links.
- #to_s ⇒ Object
Methods inherited from ModelWithItems
#count, #items_to_s, #lines_offset, #response_str
Constructor Details
#initialize(lines:) ⇒ Links
Returns a new instance of Links.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/textflight-client/models/nav.rb', line 158 def initialize(lines:) line, index = ResponseParser.line_and_index_for_beginning_with(lines: lines, string: "Links") 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 faction = hash[:faction] drag = hash[:link_drag].to_i # direction is WIP direction = Nav::GAME_LINK_TO_COMPASS_MAP[index.to_s] { index: index, drag: drag, direction: direction, faction: faction } end.sort do |a, b| Nav::COMPASS_ORDER[a[:direction]] <=> Nav::COMPASS_ORDER[b[:direction]] end end |
Instance Method Details
#to_s ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/textflight-client/models/nav.rb', line 181 def to_s table = TTY::Table.new(header: [ {value: "#{@translation}", alignment: :right}, {value: "drag", alignment: :center}, {value: "faction", alignment: :center}, {value: "original", alignment: :center}, {value: "direction", alignment: :center} ]) @items.each do |item| table << [ "#{item[:direction]}", item[:drag], item[:faction], "[#{item[:index]}]", "#{item[:direction]}" ] end table.render(:ascii, Models::TABLE_OPTIONS) do |renderer| renderer.alignments= [:right, :right, :center, :center, :center, :center] end end |