Module: UtilsURL
- Defined in:
- lib/mrpin/core/utils/utils_url.rb
Class Method Summary collapse
- .download_file_and_put_to(url_source, path_destination, callback = nil) ⇒ Object
- .to_path_absolute(path_relative) ⇒ Object
- .to_path_relative(path_absolute) ⇒ Object
Class Method Details
.download_file_and_put_to(url_source, path_destination, callback = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mrpin/core/utils/utils_url.rb', line 38 def self.download_file_and_put_to(url_source, path_destination, callback = nil) dir = File.dirname(path_destination) FileUtils.mkdir_p(dir) open(path_destination, 'wb') do |file| file << open(url_source).read unless callback.nil? callback.call end end nil end |
.to_path_absolute(path_relative) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mrpin/core/utils/utils_url.rb', line 4 def self.to_path_absolute(path_relative) result = '' if path_relative.nil? puts 'UtilsURL::to_path_absolute arg is nil' return result end protocol = Rails.env.development? ? 'http://' : 'https://' result = File.join(protocol, AppInfo.instance.host, path_relative) result end |
.to_path_relative(path_absolute) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mrpin/core/utils/utils_url.rb', line 20 def self.to_path_relative(path_absolute) result = '' if path_absolute.nil? puts 'UtilsURL::to_path_relative arg is nil' return result end result = path_absolute result.gsub!(AppInfo.instance.host, '') result.gsub!('https://', '') result.gsub!('http://', '') result end |