Sha256: 6febff807237d73af7f556a9807d01cd08a3fc7108744bb19aae355bdef41607

Contents?: true

Size: 1.5 KB

Versions: 26

Compression:

Stored size: 1.5 KB

Contents

require "enju_manifestation_viewer/engine"
require "enju_manifestation_viewer/manifestation_viewer_helper"
require "enju_manifestation_viewer/book_jacket_helper"
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
ActionView::Base.send :include, EnjuManifestationViewer::ManifestationViewerHelper
ActionView::Base.send :include, EnjuManifestationViewer::BookJacketHelper

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
enju_manifestation_viewer-0.2.4 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.2.3 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.2.2 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.2.1 lib/enju_manifestation_viewer.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/enju_manifestation_viewer-0.2.0/lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.2.0 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.2.0.beta.4 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.2.0.beta.3 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.2.0.beta.2 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.2.0.beta.1 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.1.1 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.1.0 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.1.0.pre19 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.1.0.pre18 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.1.0.pre17 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.1.0.pre16 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.1.0.pre15 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.1.0.pre14 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.1.0.pre13 lib/enju_manifestation_viewer.rb
enju_manifestation_viewer-0.1.0.pre12 lib/enju_manifestation_viewer.rb