Class: Link

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
SocialStream::Models::Object
Defined in:
app/models/link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loadedObject

Returns the value of attribute loaded.



6
7
8
# File 'app/models/link.rb', line 6

def loaded
  @loaded
end

Instance Method Details

#check_loadedObject



33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/link.rb', line 33

def check_loaded
  return if loaded.present?
  begin
    o = Linkser.parse self.url, {:max_images => 1}

    if o.is_a? Linkser::Objects::HTML
      self.fill o
    end
  rescue
  end
end

#fill(linkser_object) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/link.rb', line 16

def fill linkser_object
  self.title = linkser_object.title if linkser_object.title
  self.description = linkser_object.description if linkser_object.description
  self.url = linkser_object.last_url
  r = linkser_object.resource
  if r and r.type and r.url      
    self.callback_url = r.url
  end
  self.width  = r.width  if r and r.width
  self.height = r.height if r and r.height
  if linkser_object.ogp and linkser_object.ogp.image
    self.image = linkser_object.ogp.image
  elsif linkser_object.images and linkser_object.images.first
    self.image = linkser_object.images.first.url
  end
end

#improved_callback_urlObject



45
46
47
48
49
50
51
# File 'app/models/link.rb', line 45

def improved_callback_url
  if callback_url =~ /youtube\.com\/v\/.+/
    callback_url + '&autoplay=1'
  else
    callback_url
  end
end