Class: CSstats::Parser::FileReader

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

Defined Under Namespace

Classes: Handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FileReader.



8
9
10
11
12
13
# File 'lib/csstats/parser/file_reader.rb', line 8

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.



6
7
8
# File 'lib/csstats/parser/file_reader.rb', line 6

def file_path
  @file_path
end

#limitObject (readonly)

Returns the value of attribute limit.



6
7
8
# File 'lib/csstats/parser/file_reader.rb', line 6

def limit
  @limit
end

Instance Method Details

#read(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/csstats/parser/file_reader.rb', line 15

def read(&block)
  return unless block_given?

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

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

  read_data(file, &block)

  file.close
end