Class: DashTimelineValidator::DashFile
- Inherits:
-
Object
- Object
- DashTimelineValidator::DashFile
- Defined in:
- lib/dash_timeline_validator/file.rb
Class Method Summary collapse
- .download_and_save(uri, path) ⇒ Object
- .fetch_file(origin, file_path = Options::ANALYZER_MANIFEST_PATH) ⇒ Object
- .uri?(string) ⇒ Boolean
Class Method Details
.download_and_save(uri, path) ⇒ Object
19 20 21 22 23 |
# File 'lib/dash_timeline_validator/file.rb', line 19 def self.download_and_save(uri, path) content = Net::HTTP.get(URI.parse(uri)) File.write(path, content) content end |
.fetch_file(origin, file_path = Options::ANALYZER_MANIFEST_PATH) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/dash_timeline_validator/file.rb', line 5 def self.fetch_file(origin, file_path = Options::ANALYZER_MANIFEST_PATH) dirname = File.dirname(file_path) unless File.directory? dirname FileUtils.mkdir_p(dirname) end if uri? origin download_and_save(origin, file_path) else FileUtils.cp origin, file_path File.read file_path end end |
.uri?(string) ⇒ Boolean
25 26 27 28 29 30 31 32 |
# File 'lib/dash_timeline_validator/file.rb', line 25 def self.uri?(string) uri = URI.parse(string) %w( http https ).include?(uri.scheme) rescue URI::BadURIError false rescue URI::InvalidURIError false end |