Class: Post

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

Class Method Summary collapse

Class Method Details

.getPostIDFromPostURLString(postURLString) ⇒ Object



9
10
11
12
13
14
# File 'lib/Post.rb', line 9

def self.getPostIDFromPostURLString(postURLString)
  uri = URI.parse(postURLString)
  postID = uri.path.split('/').last.split('-').last
  
  postID
end

.getPostPathFromPostURLString(postURLString) ⇒ Object



16
17
18
19
20
21
# File 'lib/Post.rb', line 16

def self.getPostPathFromPostURLString(postURLString)
  uri = URI.parse(postURLString)
  postPath = uri.path.split('/').last
  
  URI.decode(postPath)
end

.parsePostContentFromHTML(html) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/Post.rb', line 23

def self.parsePostContentFromHTML(html)
  json = nil
  html.search('script').each do |script|
      match = script.to_s[/(<script>window\.__APOLLO_STATE__ \= ){1}(.*)(<\/script>){1}/,2]
      if !match.nil? && match != ""
          json = JSON.parse(match)
      end
  end

  json
end

.parsePostParagraphsFromPostContent(content, postID) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/Post.rb', line 35

def self.parsePostParagraphsFromPostContent(content, postID)
  result = content&.dig("Post:#{postID}", "content({\"postMeteringOptions\":null})", "bodyModel", "paragraphs")
  if result.nil?
    nil
  else
    result.map { |paragraph| content[paragraph["__ref"]] }
  end
end