Sha256: cb0b031901d824b4e6adcebe8c530ab739618ad21c73898fa2f33160f8f859c3

Contents?: true

Size: 1.39 KB

Versions: 7

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

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

module EhbrsRubyUtils
  module Bga
    module Parsers
      class Table < ::Aranha::Parsers::Html::Item
        ITEM_XPATH = '/'

        field :game_name, :string, './/*[@id = "table_name"]/text()'
        field :creation_time, :string, './/*[@id = "creationtime"]/text()'
        field :estimated_duration, :string, './/*[@id = "estimated_duration"]/text()'
        field :options, :node, './/*[@id = "gameoptions"]'
        field :players, :node, './/*[@id = "game_result"]'
        field :game_conceded, :node, './/*[@id = "game_conceded" and @style="display: block;"]'

        def item_xpath
          ITEM_XPATH
        end

        def data
          r = super
          %i[options players].each do |key|
            r[key] = self.class.const_get(key.to_s.camelize).from_node(r.fetch(key)).data
          end
          r[:creation_time] = process_creation_time(r[:creation_time])
          r[:game_conceded] = process_game_conceded(r[:game_conceded])
          r
        end

        private

        def process_creation_time(creation_time)
          creation_time.gsub('Criado:', '').strip
        end

        # @param node [Nokogiri::XML::Element]
        # @return [Boolean]
        def process_game_conceded(node)
          node.present?
        end

        require_sub __FILE__
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.27.1 lib/ehbrs_ruby_utils/bga/parsers/table.rb
ehbrs_ruby_utils-0.27.0 lib/ehbrs_ruby_utils/bga/parsers/table.rb
ehbrs_ruby_utils-0.26.0 lib/ehbrs_ruby_utils/bga/parsers/table.rb
ehbrs_ruby_utils-0.25.1 lib/ehbrs_ruby_utils/bga/parsers/table.rb
ehbrs_ruby_utils-0.25.0 lib/ehbrs_ruby_utils/bga/parsers/table.rb
ehbrs_ruby_utils-0.24.1 lib/ehbrs_ruby_utils/bga/parsers/table.rb
ehbrs_ruby_utils-0.24.0 lib/ehbrs_ruby_utils/bga/parsers/table.rb