class TFClient::Models::Links

Public Class Methods

new(lines:) click to toggle source
Calls superclass method TFClient::Models::Model::new
# 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

Public Instance Methods

to_s() click to toggle source
# 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