Sha256: f480d6d0dc1557baca9ceb9830d414144c8b4c9f66f4e5d80675a506c84bec04

Contents?: true

Size: 1.23 KB

Versions: 11

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$/ && (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$/ && 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$/ && (paths[1] == 'photos') && 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

11 entries across 11 versions & 1 rubygems

Version Path
enju_manifestation_viewer-0.3.5 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.4.0.rc.1 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.3.4 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.4.0.beta.2 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.4.0.beta.1 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.3.3 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.3.2 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.3.1 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.3.0 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.3.0.rc.1 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.3.0.beta.2 lib/enju_manifestation_viewer.rb