Class: EhbrsRubyUtils::Fs::ToFileFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/ehbrs_ruby_utils/fs/to_file_format.rb

Constant Summary collapse

TEXT_MIME_TYPES =
[%r{\Atext/\S+}, 'application/x-subrip'].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert_self(file) ⇒ Object



17
18
19
# File 'lib/ehbrs_ruby_utils/fs/to_file_format.rb', line 17

def convert_self(file)
  new(file).run
end

.convert_to_file(source, target) ⇒ Object



21
22
23
24
# File 'lib/ehbrs_ruby_utils/fs/to_file_format.rb', line 21

def convert_to_file(source, target)
  ::FileUtils.cp(source, target)
  convert_self(target)
end

.convert_to_string(source) ⇒ Object



26
27
28
29
30
31
# File 'lib/ehbrs_ruby_utils/fs/to_file_format.rb', line 26

def convert_to_string(source)
  ::EacRubyUtils::Fs::Temp.on_file do |target|
    convert_to_file(source, target)
    target.open('rb', &:read)
  end
end

Instance Method Details

#runObject

rubocop:disable Naming/PredicateMethod



34
35
36
37
38
39
# File 'lib/ehbrs_ruby_utils/fs/to_file_format.rb', line 34

def run # rubocop:disable Naming/PredicateMethod
  return false unless convert?

  convert
  true
end