Class: SC2Cli::Subcommands::HistoryShared::HistoryMatch
- Inherits:
-
Object
- Object
- SC2Cli::Subcommands::HistoryShared::HistoryMatch
- 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
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#descision ⇒ Object
readonly
Returns the value of attribute descision.
-
#map ⇒ Object
readonly
Returns the value of attribute map.
-
#speed ⇒ Object
readonly
Returns the value of attribute speed.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(json:) ⇒ HistoryMatch
constructor
A new instance of HistoryMatch.
- #to_s ⇒ Object
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
#date ⇒ Object (readonly)
Returns the value of attribute date.
38 39 40 |
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 38 def date @date end |
#descision ⇒ Object (readonly)
Returns the value of attribute descision.
39 40 41 |
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 39 def descision @descision end |
#map ⇒ Object (readonly)
Returns the value of attribute map.
40 41 42 |
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 40 def map @map end |
#speed ⇒ Object (readonly)
Returns the value of attribute speed.
41 42 43 |
# File 'lib/sc2cli/subcommands/history/historymatch.rb', line 41 def speed @speed end |
#type ⇒ Object (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_s ⇒ Object
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 |