Class: Linkser::Resource
- Inherits:
-
Object
- Object
- Linkser::Resource
- Defined in:
- lib/linkser/resource.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
Returns the value of attribute url.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(obj) ⇒ Resource
constructor
A new instance of Resource.
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
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/linkser/resource.rb', line 3 def height @height end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/linkser/resource.rb', line 3 def type @type end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/linkser/resource.rb', line 3 def url @url end |
#width ⇒ Object
Returns the value of attribute width.
3 4 5 |
# File 'lib/linkser/resource.rb', line 3 def width @width end |