Class: SC2Cli::Subcommands::HistoryShared::HistoryMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/sc2cli/subcommands/history/historymatch.rb

Constant Summary collapse

@@console =
Shared::Console.instance
@@decision_colour_default =
247
@@decision_colour =
{
  "Win"      => 40,
  "Loss"     => 160,
  "Left"     => 184,
  "Observer" => 33
}
@@speed =
"Unknown"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json:) ⇒ HistoryMatch

Returns a new instance of HistoryMatch.



46
47
48
49
50
51
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
78
79
80
81
82
83
84
85
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 46

def initialize(json:)
  @@console.fatal("Returned history information has a match with a missing date/time!") unless json.key?("date")
  @@console.fatal("Returned history information has a match with a missing decision!") unless json.key?("decision")
  @@console.fatal("Returned history information has a match with a missing map!") unless json.key?("map")
  @@console.fatal("Returned history information has a match with a missing type!") unless json.key?("type")

  date = json["date"]

  @@console.fatal("Returned history information has a match with a date/time that is not an integer!") unless date.kind_of?(Integer)
  @@console.fatal("Returned history information has a match with a date/time that is invalid!") unless date >= 0

  decision = json["decision"]

  @@console.fatal("Returned history information has a match with a decision that is not a string!") unless decision.kind_of?(String)
  @@console.fatal("Returned history information has a match with a decision that is blank!") if decision.empty?

  map = json["map"]

  @@console.fatal("Returned history information has a match with a map that is not a string!") unless map.kind_of?(String)
  @@console.fatal("Returned history information has a match with a map that is blank!") if map.empty?

  type = json["type"]

  @@console.fatal("Returned history information has a match with a type that is not a string!") unless type.kind_of?(String)
  @@console.fatal("Returned history information has a match with a type that is blank!") if type.empty?

  @date     = Time.at(date)
  @decision = decision
  @map      = map
  @type     = type

  if json.key?("speed") then
    speed = json["speed"]
    if speed.kind_of?(String) then
      @speed = speed unless speed.empty?
    end
  end

  @speed ||= @@speed
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



38
39
40
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 38

def date
  @date
end

#descisionObject (readonly)

Returns the value of attribute descision.



39
40
41
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 39

def descision
  @descision
end

#mapObject (readonly)

Returns the value of attribute map.



40
41
42
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 40

def map
  @map
end

#speedObject (readonly)

Returns the value of attribute speed.



41
42
43
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 41

def speed
  @speed
end

#typeObject (readonly)

Returns the value of attribute type.



42
43
44
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 42

def type
  @type
end

Instance Method Details

#to_sObject



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 89

def to_s
  result = String.new

  colour   = @@decision_colour.key?(@decision) ? @@decision_colour[@decision] : @@decision_colour_default
  date     = @date.strftime("%Y-%m-%d %H:%M:%S")
  decision = "%10.10s" % @decision
  map      = "%-36.36s" % @map
  type     = "%10.10s" % @type

  result = "#{@@console.format(colour: colour, message: decision)} #{type} #{map} #{date}\n"
  return result
end