Class: EhbrsRubyUtils::Bga::Parsers::GameInProgress

Inherits:
Aranha::Parsers::Html::ItemList
  • Object
show all
Defined in:
lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb

Constant Summary collapse

DEFAULT_STATUS =
'asyncplay'
ID_PARSER =
/table=(\d+)/.to_parser { |m| m[1].to_i }
ITEMS_XPATH =
'//*[@id = "section-play"]//a[contains(@href, "table=")]'
STATUS_CLASS_PATTERN =
/\Agametable_status_(.+)\z/.freeze
STATUS_CLASS_PARSER =
STATUS_CLASS_PATTERN.to_parser { |m| m[1] }
TABLE_COUNT_XPATH =
'//*[@id = "section-play"]/h1/span[contains(@class, "font-normal")]/span/text()'

Instance Method Summary collapse

Instance Method Details

#dataObject



17
18
19
20
21
22
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 17

def data
  {
    table_count: table_count,
    tables: items_data
  }
end

#item_data(idd) ⇒ Object



24
25
26
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 24

def item_data(idd)
  { id: parse_id(idd.fetch(:href)), status: 'asyncplay' }
end

#items_xpathObject



28
29
30
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 28

def items_xpath
  ITEMS_XPATH
end

#parse_id(href) ⇒ Integer

Parameters:

  • href (String)

Returns:

  • (Integer)


34
35
36
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 34

def parse_id(href)
  ID_PARSER.parse!(href)
end

#table_countInteger

Returns:

  • (Integer)


39
40
41
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 39

def table_count
  nokogiri.at_xpath(TABLE_COUNT_XPATH).if_present(-1) { |v| v.text.to_i }
end