class Encounter::Team

Clas for Team information

@!attribute [r] tid

@return [Integer] Team ID.

@!attribute [r] name

@return [String] Team name.

@!attribute [r] created at

@return [String] Date when team was created.

@!attribute [r] players_count

@return [Integer] Total number of players in team. Include captain,
  active players and reserve.

@!attribute [r] points

@return [Float] Sum of all team player's points.

@!attribute [r] games_count

@return [Integer] Total number of games played.

@!attribute [r] wins

@return [Integer] Total number of games won.

@!attribute [r] anthem

@return [String] URL to team anthem file.

@!attribute [r] website

@return [String] URL to team site.

@!attribute [r] forum

@return [String] URL to team external forum.

@!attribute [r] captain

@return [Encounter::Player] Team captain.

@!attribute [r] active

@return [Array<Encounter::Player>] List of active players.

@!attribute [r] reserve

@return [Array<Encounter::Player>] List of reserve players.

Constants

ID_PANEL

@private

PARSER_OBJECTS

@private

Attributes

tid[R]

Public Class Methods

new(conn, params) click to toggle source

@param [Encounter::Connection] conn @param [Hash] params You can pass values in this parameters to predefine

attributes. Any class attribute can be set.

@option params [Integer] :tid Team ID. Required option

@return [Encounter::Team] New object @raise [ArgumentError] Raised if connection is not given @raise [ArgumentError] Raised if :tid option is not defined

Calls superclass method Encounter::Base::new
# File lib/encounter/team.rb, line 57
def initialize(conn, params)
  raise ArgumentError, ':tid is needed' unless params.key? :tid

  super(conn, params)
end

Private Instance Methods

load_data() click to toggle source
# File lib/encounter/team.rb, line 109
def load_data
  dom_page = load_page('/Teams/TeamDetails.aspx', tid: tid)

  raise 'No such team' if dom_page.css('#lnkTeamName').empty?
  assign_values parse_all(dom_page.css('td#tdContentCenter').first)
end
parse_active(obj) click to toggle source
# File lib/encounter/team.rb, line 93
def parse_active(obj)
  {
    active: obj.css('#aspnetForm table:eq(2) tr td:eq(4) a').map do |a|
      parse_url_object(a)
    end
  }
end
parse_anthem(obj) click to toggle source
# File lib/encounter/team.rb, line 77
def parse_anthem(obj)
  { anthem: obj.css("#{ID_PANEL} embed").map { |r| r['src'] }.join }
end
parse_captain(obj) click to toggle source
# File lib/encounter/team.rb, line 88
def parse_captain(obj)
  obj = obj.css('#lnkCaptainInfo').first
  { captain: parse_url_object(obj) }
end
parse_reserve(obj) click to toggle source
# File lib/encounter/team.rb, line 101
def parse_reserve(obj)
  {
    reserve: obj.css('#aspnetForm table:eq(3) tr td:eq(4) a').map do |a|
      parse_url_object(a)
    end
  }
end
parse_urls(obj) click to toggle source
# File lib/encounter/team.rb, line 81
def parse_urls(obj)
  {
    website: obj.css('#lnkWebSite').map { |r| r['href'] }.join,
    forum: obj.css('#lnkForum').map { |r| r['href'] }.join
  }
end