Class: Txtar::Archive
- Inherits:
-
Object
- Object
- Txtar::Archive
- Defined in:
- lib/txtar/archive.rb
Overview
An Archive is a collection of files. It might have an optional comment, as well.
Constant Summary collapse
- FILE_MARKER =
Each file entry begins with a file marker line of the form “– FILENAME –” and is followed by zero or more file content lines making up the file data.
The comment or file content ends at the next file marker line. The file marker line must begin with the three-byte sequence “– ” and end with the three-byte sequence “ –”, but the enclosed file name can be surrounding by additional white space, all of which is stripped.
See git.io/JLyG7
Regexp.new('^-{2}\s{1}(?<filename>.*)\s{1}-{2}$')
- LINE_SEPARATOR =
"\n"
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
-
.parse(data:) ⇒ Object
Parses given String and returns a Txtar::Archive instance.
Instance Method Summary collapse
-
#initialize(comment: nil, files: []) ⇒ Archive
constructor
A new instance of Archive.
Constructor Details
#initialize(comment: nil, files: []) ⇒ Archive
Returns a new instance of Archive.
66 67 68 69 |
# File 'lib/txtar/archive.rb', line 66 def initialize(comment: nil, files: []) @comment = comment @files = files end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
22 23 24 |
# File 'lib/txtar/archive.rb', line 22 def comment @comment end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
22 23 24 |
# File 'lib/txtar/archive.rb', line 22 def files @files end |
Class Method Details
.parse(data:) ⇒ Object
Parses given String and returns a Txtar::Archive instance.
27 28 29 30 31 32 33 |
# File 'lib/txtar/archive.rb', line 27 def parse(data:) data = add_missing_newline(data.dup) lines = data.lines(LINE_SEPARATOR) new(comment: extract_comment(lines), files: extract_files(lines)) end |