Class: Uniconvert::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/uniconvert/converters/HTML.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(should_create_file = true) ⇒ HTML

Returns a new instance of HTML.



5
6
7
8
# File 'lib/uniconvert/converters/HTML.rb', line 5

def initialize(should_create_file = true)
  @create_file = should_create_file
  @encoder = HTMLEntities.new
end

Instance Attribute Details

#encoderObject

Returns the value of attribute encoder.



3
4
5
# File 'lib/uniconvert/converters/HTML.rb', line 3

def encoder
  @encoder
end

Instance Method Details

#convert_file(file) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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) ⇒ Object



31
32
33
# File 'lib/uniconvert/converters/HTML.rb', line 31

def convert_str(str)
  @encoder.encode(str, :named)
end