Module: BookmarkUrl

Included in:
String
Defined in:
lib/enju_bookmark/bookmark_url.rb

Instance Method Summary collapse

Instance Method Details

#bookmarkable?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/enju_bookmark/bookmark_url.rb', line 15

def bookmarkable?
  if self.my_host?
    url = ::Addressable::URI.parse(self)
    path = url.path.split("/").reverse
    if path[1] == "manifestations" and Manifestation.where(id: path[0]).first
      true
    else
      false
    end
  else
    true
  end
rescue ::Addressable::URI::InvalidURIError
  false
end

#bookmarkable_idObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/enju_bookmark/bookmark_url.rb', line 31

def bookmarkable_id
  if self.my_host?
    path = ::Addressable::URI.parse(self).path.split("/").reverse
    unless path[1] == "manifestations"
      nil
    else
      path[0]
    end
  end
end

#my_host?Boolean

Returns:

  • (Boolean)


2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/enju_bookmark/bookmark_url.rb', line 2

def my_host?
  url = ::Addressable::URI.parse(self)
  unless url.host
    raise ::Addressable::URI::InvalidURIError
  end
  config_url = ::Addressable::URI.parse(LibraryGroup.site_config.url)
  if url.host == config_url.host and url.port == config_url.port and ['http', 'https'].include?(url.scheme)
    true
  else
    false
  end
end