Class: Wp2hatena::Hatena::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/wp2hatena/hatena/converter.rb

Instance Method Summary collapse

Constructor Details

#initializeConverter



5
6
7
# File 'lib/wp2hatena/hatena/converter.rb', line 5

def initialize
  @convert_data = []
end

Instance Method Details

#convert(src_path, dest_path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wp2hatena/hatena/converter.rb', line 18

def convert(src_path, dest_path)
  open(src_path, 'r') do |fp|
    buffer = fp.read
    @convert_data.each do |data|
      tag = make_tag(data)
      buffer.gsub!(data[:html_tag], "[#{data[:syntax]}#{tag}]\r\n")
      puts "converted [#{data[:syntax]}#{tag}]"
    end

    buffer.gsub!("\r\n", "  \n") # 改行してくれないので、スペース2つ入れて対応
    File.write(dest_path, buffer)
  end
end

#set_convert_data(html_tag, width, height, syntax) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/wp2hatena/hatena/converter.rb', line 9

def set_convert_data(html_tag, width, height, syntax)
  @convert_data << {
      html_tag: html_tag,
      width: width,
      height: height,
      syntax: syntax
  }
end