class Uniconvert::HTML

Attributes

encoder[RW]

Public Class Methods

new(should_create_file = true) click to toggle source
# File lib/uniconvert/converters/HTML.rb, line 5
def initialize(should_create_file = true)
  @create_file = should_create_file
  @encoder = HTMLEntities.new
end

Public Instance Methods

convert_file(file) click to toggle source
# File lib/uniconvert/converters/HTML.rb, line 10
def convert_file(file)
  begin
    file_contents = File.read(file)
    converted = @encoder.encode(file_contents, :named)

    if @create_file
      translated_file_name = file + '.converted'

      File.open(translated_file_name, 'w+') do |f|
        f.write converted
      end

      `$EDITOR #{translated_file_name}`
    end

    converted.nil?
  rescue Errno::EISDIR
    false
  end
end
convert_str(str) click to toggle source
# File lib/uniconvert/converters/HTML.rb, line 31
def convert_str(str)
  @encoder.encode(str, :named)
end