Sha256: 24f6f9eedeafec410137cf95c047639cfd3792c6b7cd0172ae1ada48adab30af

Contents?: true

Size: 1.31 KB

Versions: 26

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'aranha/parsers/html/item_list'
require 'eac_ruby_utils/core_ext'

module EhbrsRubyUtils
  module Bga
    module Parsers
      class GameStats < ::Aranha::Parsers::Html::ItemList
        ITEMS_XPATH = '//table[@id = "gamelist_inner"]/tr'

        field :game_name, :string, './td[1]/a[1]/text()'
        field :table_name, :string, './td[1]/a[2]/text()'
        field :time_string, :string, './td[2]/div[1]/text()'
        field :leave_penalty, :integer, './td[4]/span[1]/text()'
        field :rank_increment, :integer, './td[4]/span[2]/text()'
        field :rank_after, :integer, './td[4]//*[@class = "gamerank_value"]/text()'
        field :players, :node, './td[3]'

        def items_xpath
          ITEMS_XPATH
        end

        def item_data(item)
          r = super
          r[:id] = table_name_to_id(r.delete(:table_name))
          r[:players] = players_data(r.delete(:players))
          r
        end

        private

        def players_data(players_node)
          ::EhbrsRubyUtils::Bga::Parsers::GameStats::Players.from_node(
            players_node
          ).data
        end

        # @param name [String]
        # @return [Integer]
        def table_name_to_id(name)
          name.gsub(/\A\#/, '').to_i
        end

        require_sub __FILE__
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.44.3 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.44.2 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.44.1 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.44.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.41.1 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.41.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.40.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.39.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.38.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.37.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.36.1 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.36.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.35.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.33.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.32.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.31.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.30.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.29.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.28.0 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
ehbrs_ruby_utils-0.27.1 lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb