Class: Linkser::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/linkser/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Resource

Returns a new instance of Resource.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/linkser/resource.rb', line 5

def initialize obj
  case obj       
  when OpenGraph::Object
    @type = obj["type"].split(".")[0] if obj["type"]
    if @type
      @url = obj[@type] if obj[@type]
      @url = obj[@type + ":url"] if @url.nil? and obj[@type + ":url"]
      @width = obj[@type + ":width"] if obj[@type + ":width"]
      @height = obj[@type + ":height"] if obj[@type + ":height"]
    end
    if @url.nil?
      ["video","audio"].each do |type|
        @url = obj[type] if obj[type]
        @url = obj[type + ":url"] if @url.nil? and obj[type + ":url"]
        @width = obj[type + ":width"] if obj[type + ":width"]
        @height = obj[type + ":height"] if obj[type + ":height"]
        if @url
          @type = type
          break
        end
      end
    end
  when Hash
    @type = obj[:type] if obj[:type]
    @url = obj[:url] if obj[:url]
    @width = obj[:width] if obj[:width]
    @height = obj[:height] if obj[:height]
  else
    raise 'Error creating the Linkser::Resource. Expecting Hash or OpenGraph::Object but got ' + obj.class.to_s
  end
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/linkser/resource.rb', line 3

def height
  @height
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/linkser/resource.rb', line 3

def type
  @type
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/linkser/resource.rb', line 3

def url
  @url
end

#widthObject

Returns the value of attribute width.



3
4
5
# File 'lib/linkser/resource.rb', line 3

def width
  @width
end