class Encounter::Player

Class for player information

@!attribute [r] uid

@return [Integer] User ID

@!attribute [r] name

@return [String] Player nickname

@!attribute [r] avatar

@return [String] URL to user's avatar

@!attribute [r] points

@return [Integer] Game points

@!attribute [r] first_name

@return [String] First name

@!attribute [r] patronymic_name

@return [String] Patronymic name

@!attribute [r] last_name

@return [String] Last name

@!attribute [r] country

@return [String] Player's home country

@!attribute [r] region

@return [String] Player's home region/province

@!attribute [r] city

@return [String] Player's home city

@!attribute [r] sex

@return [Symbol] Player's gender. Either _:male_ or _:female_

@!attribute [r] birthday

@return [String] Birthday date

@!attribute [r] height

@return [Integer] Height in cm

@!attribute [r] weight

@return [Integer] Weight in kg

@!attribute [r] email

@return [String] E-Mail address

@!attribute [r] mobile_phone

@return [String] Mobile phone number

@!attribute [r] website

@return [String] Website URL

@!attribute [r] skype

@return [String] Skype username

@!attribute [r] driver_license

@return [Array<Symbol>] Array of driver license categories

@!attribute [r] transport

@return [Array<Hash>] Array of hashes containing info about transport.
  Hash can contain _type_, _brand_, _model_, _number_ and _photo_.

Constants

ID_PREFIX

@private

ID_PREFIX_CON

@private

ID_PREFIX_INF

@private

ID_PREFIX_LOC

@private

ID_PREFIX_TRA

@private

PARSER_OBJECTS

@private

Attributes

uid[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] :uid User ID. Required option

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

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

  super(conn, params)
end

Private Instance Methods

load_data() click to toggle source
# File lib/encounter/player.rb, line 172
def load_data
  dom_page = load_page('/UserDetails.aspx', uid: uid)

  raise 'No such player' unless dom_page.css('form#MainForm').empty?
  assign_values parse_all(dom_page.css('#tdContentCenter').first)
end
parse_avatar(obj) click to toggle source
# File lib/encounter/player.rb, line 113
def parse_avatar(obj)
  o = obj.css('#enUserDetailsPanel_lnkAvatarEdit img').first
  n = o.parent.parent.next_element.css('td span').first.text
  { avatar: o['src'], name: n }
end
parse_birthday(obj) click to toggle source
# File lib/encounter/player.rb, line 119
def parse_birthday(obj)
  {
    birthday: %w[Date Year].map do |x|
                id = "##{ID_PREFIX_INF}_lblBirth#{x}TextVal"
                obj.css(id).first.text unless obj.css(id).empty?
              end.compact.join(' ')
  }
end
parse_car(obj, id) click to toggle source
# File lib/encounter/player.rb, line 141
def parse_car(obj, id)
  {
    type: parse_car_field(obj, id, 'TransportTypeText'),
    brand: parse_car_field(obj, id, 'CarMaker'),
    model: parse_car_field(obj, id, 'CarModel'),
    number: parse_car_field(obj, id, 'TransportNameText'),
    photo: obj.css("#{id}_TransportPhoto").map { |x| x['href'] }.join
  }
end
parse_car_field(obj, id, field) click to toggle source
# File lib/encounter/player.rb, line 137
def parse_car_field(obj, id, field)
  obj.css("#{id}_#{field}").map(&:text).join
end
parse_email(obj) click to toggle source
# File lib/encounter/player.rb, line 128
def parse_email(obj)
  idml = "##{ID_PREFIX_CON}_lblEmailVal noscript"
  idws = "##{ID_PREFIX_CON}_lWebSiteValue"
  {
    email: obj.css(idml).map(&:text).join,
    website: obj.css(idws).map { |r| r['href'] }.join
  }
end
parse_team(obj) click to toggle source
# File lib/encounter/player.rb, line 160
def parse_team(obj)
  obj = obj.css('#enUserDetailsPanel_lnkDomain').first
           .parent.parent.next_element

  status = :captain if obj.text.include? 'капитан'
  status = :player if obj.text.include? 'команде'
  {
    team_status: status || :single,
    team: status ? parse_url_object(obj.css('a').first) : nil
  }
end
parse_transport(obj) click to toggle source
# File lib/encounter/player.rb, line 151
def parse_transport(obj)
  {
    transport: (1..15).map do |i|
      id = "##{ID_PREFIX_TRA}_TransportRepeater_ctl#{i.to_s.rjust(2, '0')}"
      parse_car(obj, id) unless obj.css("#{id}_TransportTypeText").empty?
    end.compact
  }
end