Class: ICharger::Log::File

Inherits:
Object
  • Object
show all
Defined in:
lib/icharger/log/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ File

Returns a new instance of File.



18
19
20
21
22
23
24
25
# File 'lib/icharger/log/file.rb', line 18

def initialize(uri)
  open(uri, 'r') do |file|
    @rows = file.readlines.map { |row| ICharger::Log::Row.new(row) }
  end
  raise ArgumentError, "No records found in file" if @rows.empty?
rescue => e
  raise ArgumentError, "File does not appear to be an iCharger log (#{e})"
end

Instance Attribute Details

#rowsObject (readonly)

Returns the value of attribute rows.



8
9
10
# File 'lib/icharger/log/file.rb', line 8

def rows
  @rows
end

Class Method Details

.icharger?(uri) ⇒ ICharger::Log::File

Determines if the file at the given URI is an iCharger log file.

Parameters:

  • uri

    URI to file to read

Returns:



14
15
16
# File 'lib/icharger/log/file.rb', line 14

def self.icharger?(uri)
  File.new(uri) rescue nil
end

Instance Method Details

#channelObject



27
28
29
# File 'lib/icharger/log/file.rb', line 27

def channel
  @rows.first.channel
end

#durationObject



31
32
33
# File 'lib/icharger/log/file.rb', line 31

def duration
  @rows.last.time / 10000.0
end