Class: HandlerLink
- Inherits:
-
Object
- Object
- HandlerLink
- Defined in:
- lib/HandlerLink.rb
Constant Summary collapse
- FORMAT_IMG =
["jpg", "jpeg", "png", "gif"]
Instance Method Summary collapse
-
#get_host_link(link) ⇒ Object
получает урл - отдает домен.
- #handler_links(arra_links, link) ⇒ Object
-
#handler_prefix_link(host_link, link) ⇒ Object
добавляет scheme, если это href.
- #remove_global_unless_symbols(arra_images_links) ⇒ Object
- #remove_unless_link(arra_link) ⇒ Object
- #remove_unless_symbols(arra_images_links) ⇒ Object
Instance Method Details
#get_host_link(link) ⇒ Object
получает урл - отдает домен
5 6 7 8 |
# File 'lib/HandlerLink.rb', line 5 def get_host_link(link) uri = URI.parse(link) "#{uri.scheme}://" + uri.host end |
#handler_links(arra_links, link) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/HandlerLink.rb', line 10 def handler_links(arra_links, link) arra_links.each do |url| if url.include?("(/") uri = get_host_link(link) position = url.index("(") url[position] += uri.to_s end end end |
#handler_prefix_link(host_link, link) ⇒ Object
добавляет scheme, если это href
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/HandlerLink.rb', line 22 def handler_prefix_link(host_link, link) abort 'в качестве аргументов передайте строки' unless host_link.is_a?(String) || link.is_a?(String) if link[0] == '/' && link[1] != '/' host_link + link elsif link[0..1] == '//' uri = URI.parse(host_link) "#{uri.scheme}:#{link}" else link end end |
#remove_global_unless_symbols(arra_images_links) ⇒ Object
47 48 49 |
# File 'lib/HandlerLink.rb', line 47 def remove_global_unless_symbols(arra_images_links) arra_images_links.each { |link| link.delete!("(,;'')") } end |
#remove_unless_link(arra_link) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/HandlerLink.rb', line 51 def remove_unless_link(arra_link) arra_link.each_with_index do |link, index| arra_link[index] = "" if link[0..3] != "http" index_ending = nil FORMAT_IMG.each do |i| index_ending = i if link.include?(i) end unless index_ending == nil position = link.index(index_ending) arra_link[index] = "" if (link[position + index_ending.size] =~ /[a-z]/) end end arra_link.delete("") end |
#remove_unless_symbols(arra_images_links) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/HandlerLink.rb', line 35 def remove_unless_symbols(arra_images_links) arra_images_links.each do |image_url| if (image_url[0..3] != "http" || image_url[0..3] != "www.") && image_url.include?("(") position = image_url.index("(") image_url.reverse! position.times { image_url.chop! } image_url.reverse! image_url.delete!("(,;'')") end end end |