class Encounter::Game
Class for game announce information
@!attribute [r] domain
@return [String] Domain name.
@!attribute [r] gid
@return [Integer] Game id.
@!attribute [r] name
@return [String] Game title.
@!attribute [r] authors
@return [Array<Encounter::Player>] List of game authors.
@!attribute [r] start_time
@return [String] Game start time.
@!attribute [r] end_time
@return [String] Game end time.
@!attribute [r] money
@return [String] Game price.
@!attribute [r] type
@return [String] Game engine type. Possible values are _Real_, _Points_, _Virtual_, _Quiz_, _PhotoHunt_, _PhotoExtreme_, _Caching_, _WetWars_, _Competition_
@!attribute [r] limit
@return [Integer] Maximal allowed players in team. 0 if unlimited.
@!attribute [r] description
@return [String] Game description.
@!attribute [r] play_by
@return [String] Possible values are _Team_, _Single_.
@!attribute [r] teams_accepted
@return [Array<Encouter::Player>, Array<Encounter::Team>] List of accepted teams or players.
@!attribute [r] teams_waiting
@return [Array<Encouter::Player>, Array<Encounter::Team>] List of teams or players waiting to be accepted.
Constants
- GAME_TYPES
Attributes
Public Class Methods
@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 [String] :domain Domain
name. Required option @option params [Integer] :gid Game
ID. Required option
@todo Parse :play_by value
@return [Encounter::Game] New object @raise [ArgumentError] Raised if connection is not given @raise [ArgumentError] Raised if :domain or :gid option is not defined
Encounter::Base::new
# File lib/encounter/game.rb, line 67 def initialize(conn, params) raise ArgumentError, ':domain is needed' unless params.key? :domain raise ArgumentError, ':gid is needed' unless params.key? :gid super(conn, params) end
Private Instance Methods
# File lib/encounter/game.rb, line 138 def load_data dom_page = load_page("http://#{domain}/GameDetails.aspx", gid: gid) raise 'No such game' unless dom_page.css('#boxCenterTopUsers').empty? assign_values parse_all(dom_page.css('table.gameInfo').first) end
# File lib/encounter/game.rb, line 118 def parse_description(table) loop do table = table.next_element break if table.name == 'table' end { description: table.css('tr:eq(2)').inner_html } end
# File lib/encounter/game.rb, line 88 def parse_game_type(table) type_id = table.css('img#ImgGameType').first['src'] .match(/type\.(\d*)\.gif/).captures.first.to_i { type: GAME_TYPES[type_id] } end
# File lib/encounter/game.rb, line 98 def parse_limit(table) item = table.css('span#spanMaxTeamPlayers').first { limit: item.nil? ? 0 : item.text.match(/(\d+)/).captures.first.to_i } end
# File lib/encounter/game.rb, line 112 def parse_money(table) base = table.css('span#GameDetail_lblFeeType').first return { money: 0 } if base.nil? { money: "#{base.previous_element.text} #{base.text}" } end
# File lib/encounter/game.rb, line 94 def parse_name(table) { name: table.css('a#lnkGameTitle').first.text } end
# File lib/encounter/game.rb, line 134 def parse_player_list(div) div.css('a').map { |a| parse_url_object(a) } end
# File lib/encounter/game.rb, line 126 def parse_players(table) base = table.css('div.hr').last.parent.parent.previous_element.css('div') accepted = parse_player_list base.last waiting = parse_player_list base.first if base.size > 1 { teams_accepted: accepted, teams_waiting: waiting || [] } end
# File lib/encounter/game.rb, line 103 def parse_time(table) base = table.css('#GameDetail_YourTimeArea').first date = /(\d{2}\.\d{2}\.\d{4}\s\d{1,2}:\d{2}:\d{2})/ { start_time: base.previous_element.text.match(date).captures.first, end_time: base.next_element.text.match(date).captures.first } end