Class: ActsAsLink::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_link/link.rb

Constant Summary collapse

IMAGE_EXTENSIONS =
%w(.bmp .gif .ico .jpeg .jpg .png .psd .svg .tif .tiff .xcf)

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Link

Returns a new instance of Link.



11
12
13
14
# File 'lib/acts_as_link/link.rb', line 11

def initialize(url)
  @uri = URI.parse(url)
  raise 'Link is not an url' if (@uri.class != URI::HTTP && @uri.class != URI::HTTPS)
end

Instance Method Details

#is_an_image?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/acts_as_link/link.rb', line 21

def is_an_image?
  extension = get_extension(@uri.to_s)
  verify_if_extension_is_an_image(extension)
end

#is_broken?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/acts_as_link/link.rb', line 16

def is_broken?
  response = Net::HTTP.start(@uri.host, @uri.port) { |http| response = http.head(@uri.path.size > 0 ? @uri.path : "/")}  
  response_code_is_not_valid?(response.code)
end

#shortenObject



26
27
28
# File 'lib/acts_as_link/link.rb', line 26

def shorten
  shorten_link_with_bitly(@uri.to_s)    
end