Class: CSstats::Parser::Reader::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/csstats/parser/reader/file_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, options = {}) ⇒ FileReader

Returns a new instance of FileReader.



11
12
13
14
15
16
# File 'lib/csstats/parser/reader/file_reader.rb', line 11

def initialize(file_path, options = {})
  @file_path = file_path
  @limit = options[:limit] || 0

  raise CSstats::FileNotExist unless File.exist?(file_path.to_s)
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



9
10
11
# File 'lib/csstats/parser/reader/file_reader.rb', line 9

def file_path
  @file_path
end

#limitObject (readonly)

Returns the value of attribute limit.



9
10
11
# File 'lib/csstats/parser/reader/file_reader.rb', line 9

def limit
  @limit
end

Instance Method Details

#read(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/csstats/parser/reader/file_reader.rb', line 18

def read(&block)
  return unless block_given?

  file = File.new(file_path, 'r')

  # Need to read first data, which means file version.
  _file_version = streamer(file).read_short_data

  read_data(file, &block)

  file.close
end