Class: ActsAsLink::Link
- Inherits:
-
Object
- Object
- ActsAsLink::Link
- 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
-
#initialize(url) ⇒ Link
constructor
A new instance of Link.
- #is_an_image? ⇒ Boolean
- #is_broken? ⇒ Boolean
- #shorten ⇒ Object
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
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
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 |
#shorten ⇒ Object
26 27 28 |
# File 'lib/acts_as_link/link.rb', line 26 def shorten shorten_link_with_bitly(@uri.to_s) end |