Class: TFClient::Models::Nav

Inherits:
Response show all
Defined in:
lib/textflight-client/models/nav.rb

Constant Summary collapse

{
  "0" => "sw",
  "1" => "s",
  "2" => "se",
  "3" => "w",
  "4" => "e",
  "5" => "nw",
  "6" => "n",
  "7" => "ne"
}
{
  "n" => 6,
  "ne" => 7,
  "e" => 4,
  "se" => 2,
  "s" => 1,
  "sw" => 0,
  "w" => 3,
  "nw" => 5
}
COMPASS_ORDER =
{
  "n" => 0,
  "ne" => 1,
  "e" => 2,
  "se" => 3,
  "s" => 4,
  "sw" => 5,
  "w" => 6,
  "nw" => 7
}
LINE_IDENTIFIER =
[
  "Coordinates",
  "Claimed by",
  "Brightness",
  "Asteroids",
  "Links",
  "Planets",
  "Structures"
].freeze

Instance Attribute Summary collapse

Attributes inherited from Response

#lines

Instance Method Summary collapse

Constructor Details

#initialize(lines:) ⇒ Nav

Returns a new instance of Nav.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/textflight-client/models/nav.rb', line 52

def initialize(lines:)
  super(lines: lines)

  LINE_IDENTIFIER.each_with_index do |label, label_index|
    var_name = ResponseParser.snake_case_sym_from_string(string: label)
    class_name = ResponseParser.camel_case_from_string(string: label)

    clazz = ResponseParser.model_class_from_string(string: class_name)
    if clazz.nil?
      raise "could not find class name: #{class_name}"
    end

    line, _ = ResponseParser.line_and_index_for_beginning_with(lines: @lines,
                                                               string: label)

    next if line.nil?

    if label_index < 4
      var = clazz.new(line: line)
    else
      var = clazz.new(lines: @lines)
    end

    instance_variable_set("@#{var_name}", var)
  end
end

Instance Attribute Details

#asteroidsObject (readonly)

Returns the value of attribute asteroids.



49
50
51
# File 'lib/textflight-client/models/nav.rb', line 49

def asteroids
  @asteroids
end

#brightnessObject (readonly)

Returns the value of attribute brightness.



49
50
51
# File 'lib/textflight-client/models/nav.rb', line 49

def brightness
  @brightness
end

#claimed_byObject (readonly)

Returns the value of attribute claimed_by.



49
50
51
# File 'lib/textflight-client/models/nav.rb', line 49

def claimed_by
  @claimed_by
end

#coordinatesObject (readonly)

Returns the value of attribute coordinates.



49
50
51
# File 'lib/textflight-client/models/nav.rb', line 49

def coordinates
  @coordinates
end

Returns the value of attribute links.



50
51
52
# File 'lib/textflight-client/models/nav.rb', line 50

def links
  @links
end

#planetsObject (readonly)

Returns the value of attribute planets.



50
51
52
# File 'lib/textflight-client/models/nav.rb', line 50

def planets
  @planets
end

#structuresObject (readonly)

Returns the value of attribute structures.



50
51
52
# File 'lib/textflight-client/models/nav.rb', line 50

def structures
  @structures
end

Instance Method Details

#responseObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/textflight-client/models/nav.rb', line 79

def response
  puts @planets

  puts @links
  table = TTY::Table.new(rows: [[
    "#{@brightness.to_s}",
    "#{@asteroids.to_s}",
    "#{@coordinates}"]
  ])

  puts table.render(:ascii, Models::TABLE_OPTIONS) do |renderer|
    renderer.alignments= [:left, :center, :right]
  end

  puts @structures
end

#to_sObject



96
97
98
# File 'lib/textflight-client/models/nav.rb', line 96

def to_s
  "#<Nav: #{@coordinates.to_s}>"
end