Class: SC2Cli::Subcommands::HistoryShared::HistoryMatches
- Inherits:
-
Object
- Object
- SC2Cli::Subcommands::HistoryShared::HistoryMatches
- Defined in:
- lib/sc2cli/subcommands/history/historymatches.rb
Instance Method Summary collapse
- #add(match:) ⇒ Object
-
#initialize(json:) ⇒ HistoryMatches
constructor
A new instance of HistoryMatches.
- #to_s ⇒ Object
Constructor Details
#initialize(json:) ⇒ HistoryMatches
Returns a new instance of HistoryMatches.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sc2cli/subcommands/history/historymatches.rb', line 23 def initialize(json:) @matches = Array.new if json.key?("matches") then matches = json["matches"] @@console.fatal("Returned history information matches is not an array!") unless matches.kind_of?(Array) matches.each do |match| match = HistoryMatch.new(json: match) add(match: match) end end end |
Instance Method Details
#add(match:) ⇒ Object
39 40 41 42 |
# File 'lib/sc2cli/subcommands/history/historymatches.rb', line 39 def add(match:) @matches << match if match.kind_of?(HistoryMatch) @matches.sort_by!{ |match| match.date }.reverse! end |
#to_s ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/sc2cli/subcommands/history/historymatches.rb', line 46 def to_s result = String.new @matches.each do |match| result += match.to_s end return result end |