class Onebox::Engine::PastebinOnebox

Constants

MAX_LINES

Private Instance Methods

content() click to toggle source
# File lib/onebox/engine/pastebin_onebox.rb, line 24
def content
  lines.take(MAX_LINES).join("\n")
end
data() click to toggle source
# File lib/onebox/engine/pastebin_onebox.rb, line 15
def data
  @data ||= {
    title: 'pastebin.com',
    link: link,
    content: content,
    truncated?: truncated?
  }
end
lines() click to toggle source
# File lib/onebox/engine/pastebin_onebox.rb, line 32
def lines
  return @lines if defined?(@lines)
  response = Onebox::Helpers.fetch_response("http://pastebin.com/raw/#{paste_key}", redirect_limit: 1) rescue ""
  @lines = response.split("\n")
end
paste_key() click to toggle source
# File lib/onebox/engine/pastebin_onebox.rb, line 38
def paste_key
  regex = case uri
          when /\/raw\//
            /\/raw\/([^\/]+)/
          when /\/download\//
            /\/download\/([^\/]+)/
          when /\/embed\//
            /\/embed\/([^\/]+)/
  else
            /\/([^\/]+)/
  end

  match = uri.path.match(regex)
  match[1] if match && match[1]
end
truncated?() click to toggle source
# File lib/onebox/engine/pastebin_onebox.rb, line 28
def truncated?
  lines.size > MAX_LINES
end