Class: EmbedRb::OpenGraph_

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/embedrb/embed_open_graph.rb

Instance Method Summary collapse

Methods included from Base

#embed, #shorten, #url_to_text

Constructor Details

#initialize(input, output, options, embeds) ⇒ OpenGraph_

Returns a new instance of OpenGraph_.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/embedrb/embed_open_graph.rb', line 9

def initialize(input, output, options, embeds)
  @input = input
  @output = output
  @options = options
  @embeds = embeds
  @url_regex = EmbedRb.url_regex
  pattern = ['flickr\.com|youtube\.com|youtu\.be|\.mp4|\.ogv|\.webm|\.mp3|\.wav|\.gif|\.pdf|\.doc|\.ppt|\.docx|\.jpg|\.jpeg|\.tiff|\.png|\.svg|\.webp|\.ogg']
  openGraphOptions = options[:openGraphOptions]
  if openGraphOptions[:excluded_regex]
    pattern[1] = openGraphOptions[:excluded_regex]
  end
  @excluded_regex = Regexp.new(pattern.join("|"), Regexp::IGNORECASE)
end

Instance Method Details

#processObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/embedrb/embed_open_graph.rb', line 23

def process()
  @input.scan(@url_regex) {|match|
    url = match[2]
    short_url = shorten(url)
    if !exclude?(url) && !@options[:served].include?(short_url) && EmbedRb.process_more?(@options, :openGraphEndpoint, @embeds)
      data = fetch(url)
      if data
        @options[:served] << short_url
        @embeds << {
          :key => url,
          :text => render(data)
        }
      end
    end
  }

  @output
end