Class: SC2Cli::Subcommands::Ladder
- Inherits:
-
Object
- Object
- SC2Cli::Subcommands::Ladder
- Defined in:
- lib/sc2cli/subcommands/ladder.rb
Constant Summary collapse
Instance Method Summary collapse
-
#initialize(configuration:, options:) ⇒ Ladder
constructor
A new instance of Ladder.
- #run ⇒ Object
Constructor Details
#initialize(configuration:, options:) ⇒ Ladder
Returns a new instance of Ladder.
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 86 87 88 |
# File 'lib/sc2cli/subcommands/ladder.rb', line 48 def initialize(configuration:, options:) @configuration = configuration id = nil name = nil region = nil OptionParser.new do |opts| opts. = "Usage: #{$0} #{self.class.name.split("::").last.downcase} [options]" opts.on("-h", "--help", "Prints this help") do @@console.info(opts) exit end opts.on("-i", "--id ID", Integer, "Player profile ID.") do |value| id = value end opts.on("-n", "--name NAME", String, "Player name. Must exist in names file.") do |value| name = value end opts.on("-r", "--region REGION", String, "Region name, such as 'eu' or 'us'. Use configuration region by default.") do |value| region = Shared::Region.new(name: value) end end.parse! if name.kind_of?(String) then name = Shared::Names.new(configuration: @configuration, name: name) id = name.id region ||= name.region end region ||= @configuration.region @@console.fatal("Player profile ID or name must be specified!") unless id.kind_of?(Integer) @id = id @region = region end |
Instance Method Details
#run ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sc2cli/subcommands/ladder.rb', line 92 def run @@console.info("Finding ladder summary:") @@console.info(" - ID : #{@id.to_s}") @@console.info(" - Region: #{@region.description}") path = "#{@@prefix}/#{@region.id.to_s}/#{@region.realm.to_s}/#{@id.to_s}#{@@suffix}" api = Shared::Api.new(configuration: @configuration, region: @region) result = api.get(path: path) ladders = LadderShared::LadderSummary.new(json: result, api: api, player: @id) @@console.info(ladders.to_s) end |