Class: EmbedRb::OpenGraph
- Inherits:
-
Object
- Object
- EmbedRb::OpenGraph
- Includes:
- Base
- Defined in:
- lib/embedrb/embed_open_graph.rb
Instance Method Summary collapse
-
#initialize(input, output, options, embeds) ⇒ OpenGraph
constructor
A new instance of OpenGraph.
- #process ⇒ Object
Methods included from Base
#embed, #shorten, #url_to_text
Constructor Details
#initialize(input, output, options, embeds) ⇒ OpenGraph
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/embedrb/embed_open_graph.rb', line 10 def initialize(input, output, , ) @input = input @output = output @options = @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 = [:openGraphOptions] if openGraphOptions[:excluded_regex] pattern[1] = openGraphOptions[:excluded_regex] end @excluded_regex = Regexp.new(pattern.join("|"), Regexp::IGNORECASE) end |
Instance Method Details
#process ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/embedrb/embed_open_graph.rb', line 24 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) p short_url data = fetch(url) if data @options[:served] << short_url @embeds << { :key => url, :text => render(data) } end end } @output end |