Class: AppleEpf::Parser
- Inherits:
-
Object
- Object
- AppleEpf::Parser
- Defined in:
- lib/apple_epf/parser.rb
Constant Summary collapse
- FIELD_SEPARATOR =
1.chr
- RECORD_SEPARATOR =
2.chr + "\n"
- COMMENT_CHAR =
'#'
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#footer_info ⇒ Object
Returns the value of attribute footer_info.
-
#header_info ⇒ Object
Returns the value of attribute header_info.
Instance Method Summary collapse
-
#initialize(filename) ⇒ Parser
constructor
A new instance of Parser.
- #parse_metadata ⇒ Object
- #process_rows(&block) ⇒ Object
Constructor Details
#initialize(filename) ⇒ Parser
Returns a new instance of Parser.
9 10 11 12 13 |
# File 'lib/apple_epf/parser.rb', line 9 def initialize(filename) @filename = filename @header_info = {} @footer_info = {} end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
7 8 9 |
# File 'lib/apple_epf/parser.rb', line 7 def filename @filename end |
#footer_info ⇒ Object
Returns the value of attribute footer_info.
7 8 9 |
# File 'lib/apple_epf/parser.rb', line 7 def @footer_info end |
#header_info ⇒ Object
Returns the value of attribute header_info.
7 8 9 |
# File 'lib/apple_epf/parser.rb', line 7 def header_info @header_info end |
Instance Method Details
#parse_metadata ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/apple_epf/parser.rb', line 15 def begin parse_file load_header_info @header_info.merge(@footer_info) ensure close_file end end |
#process_rows(&block) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/apple_epf/parser.rb', line 26 def process_rows(&block) File.foreach( @filename, RECORD_SEPARATOR ) do |line| unless line[0].chr == COMMENT_CHAR line = line.chomp( RECORD_SEPARATOR ) block.call( line.split( FIELD_SEPARATOR, -1) ) if block_given? end end end |