Sha256: 2bd81675067ee70134e359f21d3e00a2214a4180ca8ff8b4c3fa7e872a457a91

Contents?: true

Size: 840 Bytes

Versions: 2

Compression:

Stored size: 840 Bytes

Contents

module Linkser
  class Resource    
    attr_accessor :type, :url, :width, :height
    
    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
      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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
linkser-0.0.6 lib/linkser/resource.rb
linkser-0.0.5 lib/linkser/resource.rb