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



19
20
21
# File 'lib/ehbrs_ruby_utils/fs/to_file_format.rb', line 19

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

.convert_to_file(source, target) ⇒ Object



23
24
25
26
# File 'lib/ehbrs_ruby_utils/fs/to_file_format.rb', line 23

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

.convert_to_string(source) ⇒ Object



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

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



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

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

  convert
  true
end