Class: Onebox::Preview

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

Defined Under Namespace

Classes: InvalidURI

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(link, parameters = Onebox.options) ⇒ Preview

Returns a new instance of Preview.



5
6
7
8
9
10
# File 'lib/onebox/preview.rb', line 5

def initialize(link, parameters = Onebox.options)
  @url = link
  @options = parameters
  @cache = options.cache
  @engine_class = Matcher.new(@url).oneboxed
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



3
4
5
# File 'lib/onebox/preview.rb', line 3

def cache
  @cache
end

Class Method Details

.web_exceptionsObject



30
31
32
# File 'lib/onebox/preview.rb', line 30

def self.web_exceptions
 [Net::HTTPServerException, OpenURI::HTTPError, Timeout::Error, Net::HTTPError, Errno::ECONNREFUSED]
end

Instance Method Details

#optionsObject



26
27
28
# File 'lib/onebox/preview.rb', line 26

def options
  OpenStruct.new(@options)
end

#placeholder_htmlObject



19
20
21
22
23
24
# File 'lib/onebox/preview.rb', line 19

def placeholder_html
  return "" unless engine
  process_html(engine.placeholder_html)
rescue *Onebox::Preview.web_exceptions
  ""
end

#to_sObject



12
13
14
15
16
17
# File 'lib/onebox/preview.rb', line 12

def to_s
  return "" unless engine
  process_html(engine_html)
rescue *Onebox::Preview.web_exceptions
  ""
end