Class: JohnStamos::ExtractionHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/john_stamos/extraction_helper.rb

Class Method Summary collapse

Class Method Details

.embedded_page_json(page_content) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/john_stamos/extraction_helper.rb', line 2

def self.embedded_page_json(page_content)
  seed_json_identifier = 'P.start.start'

  embedded_script = page_content.search('script').select do |script|
    script['src'].nil? && script.content.include?(seed_json_identifier)
  end

  embedded_script_content = embedded_script.last.content
  # This regex used in the range snatches the parameter Pinterest uses to
  # start their app... This parameter happens to be a JSON representation of
  # the page.
  raw_json = embedded_script_content[/#{seed_json_identifier}\((.*)\);/m, 1]

  JSON.parse(raw_json)
end