Class: EdifactConverter::EDI2XML11::PositionIO
- Inherits:
-
Object
- Object
- EdifactConverter::EDI2XML11::PositionIO
- Defined in:
- lib/edifact_converter/edi2xml11/position_io.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#file ⇒ Object
Returns the value of attribute file.
-
#line ⇒ Object
Returns the value of attribute line.
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #binread(amount) ⇒ Object
- #close ⇒ Object
-
#initialize(file) ⇒ PositionIO
constructor
A new instance of PositionIO.
- #position ⇒ Object
- #read(amount = 1) ⇒ Object
- #unread(amount = 1) ⇒ Object
Constructor Details
#initialize(file) ⇒ PositionIO
8 9 10 11 12 13 |
# File 'lib/edifact_converter/edi2xml11/position_io.rb', line 8 def initialize(file) @file = file @file.set_encoding (Encoding::ASCII_8BIT) @column = @line = 0 @lines = [] end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
6 7 8 |
# File 'lib/edifact_converter/edi2xml11/position_io.rb', line 6 def column @column end |
#file ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/edifact_converter/edi2xml11/position_io.rb', line 6 def file @file end |
#line ⇒ Object
Returns the value of attribute line.
6 7 8 |
# File 'lib/edifact_converter/edi2xml11/position_io.rb', line 6 def line @line end |
#lines ⇒ Object
Returns the value of attribute lines.
6 7 8 |
# File 'lib/edifact_converter/edi2xml11/position_io.rb', line 6 def lines @lines end |
Instance Method Details
#binread(amount) ⇒ Object
60 61 62 63 |
# File 'lib/edifact_converter/edi2xml11/position_io.rb', line 60 def binread(amount) @column += amount @file.read amount end |
#close ⇒ Object
69 70 71 |
# File 'lib/edifact_converter/edi2xml11/position_io.rb', line 69 def close @file.close end |
#position ⇒ Object
65 66 67 |
# File 'lib/edifact_converter/edi2xml11/position_io.rb', line 65 def position Position.new @line, @column end |
#read(amount = 1) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/edifact_converter/edi2xml11/position_io.rb', line 15 def read(amount = 1) text = '' while(amount > 0) nextchar = @file.getc raise EOFError.new unless nextchar nextchar.encode!(Encoding::UTF_8, Encoding::ISO_8859_1) #force_encoding Encoding::ISO_8859_1 case nextchar when /\n/ @lines[@line] = @column @line += 1 @column = 0 when /\r/ @column += 1 else text << nextchar amount -= 1 @column += 1 end end text end |
#unread(amount = 1) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/edifact_converter/edi2xml11/position_io.rb', line 37 def unread(amount = 1) while amount > 0 @file.pos -= 1 old_pos = @file.pos nextchar = @file.getc # Hack for windows if @file.pos - old_pos > 1 @file.pos -= 3 nextchar = @file.getc end @file.pos -= 1 case nextchar when /\r/ when /\n/ @line -= 1 @column = @lines[@line] else @column -= 1 amount -= 1 end end end |