Class: EhbrsRubyUtils::Bga::Parsers::GameInProgress
- Inherits:
-
Aranha::Parsers::Html::ItemList
- Object
- Aranha::Parsers::Html::ItemList
- EhbrsRubyUtils::Bga::Parsers::GameInProgress
- 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=")]'- NO_TABLES_XPATH =
'//p[normalize-space(text()) = "Nenhum jogo em andamento"]'- STATUS_CLASS_PATTERN =
/\Agametable_status_(.+)\z/- 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
- #data ⇒ Object
- #item_data(idd) ⇒ Object
- #items_xpath ⇒ Object
- #no_tables? ⇒ Boolean
- #no_tables_count ⇒ Integer
- #parse_id(href) ⇒ Integer
- #table_count ⇒ Integer
Instance Method Details
#data ⇒ Object
18 19 20 21 22 23 |
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 18 def data { table_count: table_count, tables: items_data } end |
#item_data(idd) ⇒ Object
25 26 27 |
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 25 def item_data(idd) { id: parse_id(idd.fetch(:href)), status: 'asyncplay' } end |
#items_xpath ⇒ Object
29 30 31 |
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 29 def items_xpath ITEMS_XPATH end |
#no_tables? ⇒ Boolean
50 51 52 |
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 50 def no_tables? nokogiri.at_xpath(NO_TABLES_XPATH).present? end |
#no_tables_count ⇒ Integer
45 46 47 |
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 45 def no_tables_count no_tables? ? 0 : -1 end |
#parse_id(href) ⇒ Integer
35 36 37 |
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 35 def parse_id(href) ID_PARSER.parse!(href) end |
#table_count ⇒ Integer
40 41 42 |
# File 'lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb', line 40 def table_count nokogiri.at_xpath(TABLE_COUNT_XPATH).if_present(no_tables_count) { |v| v.text.to_i } end |