Class: TradingviewScreener::ScreenData::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/tradingview_screener/screen_data.rb

Constant Summary collapse

SCREEN_DATA_RE =
/window\.initData\.screen_data\s*=\s*(\{.*?\})\s*;\s*\n\s*window\.initData\.onScreenerStandalonePage/m

Class Method Summary collapse

Class Method Details

.extract_screen_data(html) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/tradingview_screener/screen_data.rb', line 52

def self.extract_screen_data(html)
  text = html.to_s
  match = text.match(SCREEN_DATA_RE)
  raise ParseError, "screen_data not found in HTML" unless match

  JSON.parse(match[1])
rescue JSON::ParserError => e
  raise ParseError, "invalid screen_data JSON: #{e.message}"
end