Class: Resedit::Text
- Inherits:
-
Object
- Object
- Resedit::Text
- Defined in:
- lib/resedit/text/text.rb
Constant Summary collapse
- TYPE_TXT =
'txt'
- TYPE_XML =
'xml'
Instance Attribute Summary collapse
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#escaper ⇒ Object
Returns the value of attribute escaper.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#userData ⇒ Object
Returns the value of attribute userData.
Instance Method Summary collapse
- #addLine(line, meta = nil) ⇒ Object
- #getLine(id) ⇒ Object
-
#initialize(format = TYPE_TXT, encoding = nil) ⇒ Text
constructor
A new instance of Text.
- #load(filename, count = nil) ⇒ Object
- #save(filename) ⇒ Object
- #setFormat(format) ⇒ Object
Constructor Details
#initialize(format = TYPE_TXT, encoding = nil) ⇒ Text
Returns a new instance of Text.
14 15 16 17 18 19 20 21 |
# File 'lib/resedit/text/text.rb', line 14 def initialize(format=TYPE_TXT,encoding=nil) @encoding = encoding format=TYPE_TXT if !format setFormat(format) @escaper = StdEscaper.new() @lines = [] @meta={} end |
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
10 11 12 |
# File 'lib/resedit/text/text.rb', line 10 def encoding @encoding end |
#escaper ⇒ Object
Returns the value of attribute escaper.
10 11 12 |
# File 'lib/resedit/text/text.rb', line 10 def escaper @escaper end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
9 10 11 |
# File 'lib/resedit/text/text.rb', line 9 def format @format end |
#formatter ⇒ Object
Returns the value of attribute formatter.
10 11 12 |
# File 'lib/resedit/text/text.rb', line 10 def formatter @formatter end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
9 10 11 |
# File 'lib/resedit/text/text.rb', line 9 def lines @lines end |
#meta ⇒ Object
Returns the value of attribute meta.
10 11 12 |
# File 'lib/resedit/text/text.rb', line 10 def @meta end |
#userData ⇒ Object
Returns the value of attribute userData.
10 11 12 |
# File 'lib/resedit/text/text.rb', line 10 def userData @userData end |
Instance Method Details
#addLine(line, meta = nil) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/resedit/text/text.rb', line 35 def addLine(line, = nil) line.encode!("utf-8",@encoding) if @encoding line.force_encoding('utf-8') @lines += [line] @meta[@lines.length-1]= end |
#getLine(id) ⇒ Object
42 43 44 45 46 |
# File 'lib/resedit/text/text.rb', line 42 def getLine(id) line = @lines[id] line.encode!(@encoding) if @encoding return line end |
#load(filename, count = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/resedit/text/text.rb', line 59 def load(filename, count=nil) @lines = @formatter.loadLines(filename) raise "Wrong lines count: #{filename} #{count} #{@lines.length}" if count && count!=@lines.length if @escaper nl=[] @lines.each {|l| nl += [@escaper.unescape(l)] } @lines = nl end end |
#save(filename) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/resedit/text/text.rb', line 48 def save(filename) nl=@lines if @escaper nl=[] @lines.each{|l| nl += [@escaper.escape(l)] } end @formatter.saveLines(filename, nl, @meta) end |
#setFormat(format) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/resedit/text/text.rb', line 23 def setFormat(format) if format == TYPE_TXT @format = format @formatter=FormatTxt.new(@encoding) elsif format == TYPE_XML @format = format @formatter=FormatXml.new(@encoding) else raise "Unsupported format " + format end end |