Class: Diff2Xml::Diff2Rss20

Inherits:
Object
  • Object
show all
Includes:
Handler, XmlTool
Defined in:
lib/diff2xml/diff2rss20.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XmlTool

#convert_illegal_characters, #convert_space, #sanitize

Constructor Details

#initialize(os = STDOUT, url = 'http://localhost/', title = 'Diff2Xml', desc = 'Diff RSS', lang = 'en-us') ⇒ Diff2Rss20

Returns a new instance of Diff2Rss20.



44
45
46
47
48
49
50
51
52
# File 'lib/diff2xml/diff2rss20.rb', line 44

def initialize(os = STDOUT, url = 'http://localhost/', title = 'Diff2Xml', desc = 'Diff RSS', lang = 'en-us')
  @ostream = os
  @url = url
  @title = title
  @desc = desc
  @lang = lang
  @now = Time.now
  @str_buffer = ''
end

Instance Attribute Details

#descObject

Returns the value of attribute desc.



38
39
40
# File 'lib/diff2xml/diff2rss20.rb', line 38

def desc
  @desc
end

#langObject

Returns the value of attribute lang.



38
39
40
# File 'lib/diff2xml/diff2rss20.rb', line 38

def lang
  @lang
end

#ostream=(value) ⇒ Object (writeonly)

Sets the attribute ostream

Parameters:

  • value

    the value to set the attribute ostream to.



39
40
41
# File 'lib/diff2xml/diff2rss20.rb', line 39

def ostream=(value)
  @ostream = value
end

#titleObject

Returns the value of attribute title.



38
39
40
# File 'lib/diff2xml/diff2rss20.rb', line 38

def title
  @title
end

#urlObject

Returns the value of attribute url.



38
39
40
# File 'lib/diff2xml/diff2rss20.rb', line 38

def url
  @url
end

Instance Method Details

#common_line(line) ⇒ Object



113
114
115
116
# File 'lib/diff2xml/diff2rss20.rb', line 113

def common_line(line)
  line = sanitize(line)
  @str_buffer << "<tr><td bgcolor=\"#dddddd\"><tt>#{line}</tt></td></tr>"
end

#end_blockObject



99
100
101
# File 'lib/diff2xml/diff2rss20.rb', line 99

def end_block
  @str_buffer << "</table>"
end

#end_documentObject



88
89
90
# File 'lib/diff2xml/diff2rss20.rb', line 88

def end_document
  @str_buffer << "]]>\n</description>\n</item>"
end

#end_parseObject



69
70
71
72
73
# File 'lib/diff2xml/diff2rss20.rb', line 69

def end_parse
  @str_buffer << "</channel>\n</rss>"
  @str_buffer = Kconv.toutf8(@str_buffer)
  @ostream.print @str_buffer
end

#source_line(line) ⇒ Object



103
104
105
106
# File 'lib/diff2xml/diff2rss20.rb', line 103

def source_line(line)
  line = sanitize(line)
  @str_buffer << "<tr><td bgcolor=\"#aaaaaa\"><tt>#{line}</tt></td></tr>"
end

#start_block(sourceBase, sourceLength, targetBase, targetLength) ⇒ Object



92
93
94
95
96
97
# File 'lib/diff2xml/diff2rss20.rb', line 92

def start_block(sourceBase, sourceLength, targetBase, targetLength)
  @str_buffer << <<BLOCK
<h3>From #{sourceBase} to #{sourceBase.to_i+sourceLength.to_i}</h3>
<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">
BLOCK
end

#start_document(source, target) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/diff2xml/diff2rss20.rb', line 75

def start_document(source, target)
  @str_buffer << <<HEADER
<item>
<title>#{source}</title>
<link>#{@url}##{source}</link>
<author>Diff2Xml::Diff2Rss20</author>
<pubDate>#{@now}</pubDate>
<description>
<![CDATA[
HEADER
  @now = @now.succ
end

#start_parseObject

Override



58
59
60
61
62
63
64
65
66
67
# File 'lib/diff2xml/diff2rss20.rb', line 58

def start_parse
  @str_buffer << <<HEAD
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\">
<channel>
<title>#{@title}</title>
<description>#{@desc}</description>
<language>#{@lang}/language>
HEAD
end

#target_line(line) ⇒ Object



108
109
110
111
# File 'lib/diff2xml/diff2rss20.rb', line 108

def target_line(line)
  line = sanitize(line)
  @str_buffer << "<tr><td bgcolor=\"#ffff00\"><tt>#{line}</tt></td></tr>"
end