Class: CnabRb::Format::File
- Inherits:
-
Object
- Object
- CnabRb::Format::File
- Defined in:
- lib/cnab_rb/format/file.rb
Direct Known Subclasses
Constant Summary collapse
- LINE_BREAK =
"\r\n"
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #decode(text) ⇒ Object
- #encode ⇒ Object
- #get_line_layout(line_text) ⇒ Object
-
#initialize ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize ⇒ File
Returns a new instance of File.
7 8 9 |
# File 'lib/cnab_rb/format/file.rb', line 7 def initialize @lines = [] end |
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
3 4 5 |
# File 'lib/cnab_rb/format/file.rb', line 3 def lines @lines end |
Instance Method Details
#decode(text) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cnab_rb/format/file.rb', line 15 def decode(text) @lines = text.split(LINE_BREAK).map do |line_text| layout = get_line_layout(line_text) unless layout.nil? line = Line.new(layout) line.decode(line_text) line end end @lines = @lines.filter {|n| !n.nil?} end |
#encode ⇒ Object
11 12 13 |
# File 'lib/cnab_rb/format/file.rb', line 11 def encode @lines.map{|line| line.encode}.join(LINE_BREAK) end |