Class: AppleEpf::Parser

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#filenameObject

Returns the value of attribute filename.



7
8
9
# File 'lib/apple_epf/parser.rb', line 7

def filename
  @filename
end

Returns the value of attribute footer_info.



7
8
9
# File 'lib/apple_epf/parser.rb', line 7

def footer_info
  @footer_info
end

#header_infoObject

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_metadataObject



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
    load_footer_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