Sha256: 961e094f5a2a49852b4e9e509f38c6d36ca733ad1f87997b0a6a92f0ba0543de

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require "enju_manifestation_viewer/engine"
require "addressable/uri"

module EnjuManifestationViewer
  def self.included(base)
    base.extend ClassMethods
  end

  module ClassMethods
    def enju_manifestation_viewer
      include EnjuManifestationViewer::InstanceMethods
    end
  end

  module InstanceMethods
    def youtube_id
      if access_address
        url = ::Addressable::URI.parse(access_address)
        if url.host =~ /youtube\.com$/ and url.path == "/watch"
          return CGI.parse(url.query)["v"][0]
        end
      end
    end

    def nicovideo_id
      if access_address
        url = ::Addressable::URI.parse(access_address)
        if url.host =~ /nicovideo\.jp$/ and url.path =~ /^\/watch/
          return url.path.split("/")[2]
        end
      end
    end

    def flickr
      if access_address
        url = ::Addressable::URI.parse(access_address)
        paths = url.path.split('/')
        if url.host =~ /^www\.flickr\.com$/ and paths[1] == 'photos' and paths[2]
          info = {}
          if paths[3] == "sets"
            info[:user] = paths[2]
            info[:set_id] = paths[4]
            return info
          end
        end
      end
    end
  end
end

ActiveRecord::Base.send :include, EnjuManifestationViewer

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
enju_manifestation_viewer-0.3.0.beta.1 lib/enju_manifestation_viewer.rb