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



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.



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

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

Instance Method Details

#capacitiesObject



57
58
59
# File 'lib/icharger/log/file.rb', line 57

def capacities
  @rows.map(&:capacity)
end

#cell_countObject



81
82
83
# File 'lib/icharger/log/file.rb', line 81

def cell_count
  @rows.map(&:cell_count).max
end

#cell_voltages(index) ⇒ Object



77
78
79
# File 'lib/icharger/log/file.rb', line 77

def cell_voltages(index)
  @rows.each_with_object(index).map(&:cell_voltage)
end

#channelNumber

Gets the charger channel number.



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

def channel
  @rows.first.channel
end

#currentsObject



45
46
47
# File 'lib/icharger/log/file.rb', line 45

def currents
  @rows.map(&:current)
end

#durationFloat

Gets the duration of the log, in seconds.



37
38
39
# File 'lib/icharger/log/file.rb', line 37

def duration
  @rows.last.time / 10000.0
end

#external_temperatures(unit = :c) ⇒ Object



73
74
75
# File 'lib/icharger/log/file.rb', line 73

def external_temperatures(unit = :c)
  @rows.each_with_object(unit).map(&:internal_temperature)
end

#external_temperatures?Boolean



69
70
71
# File 'lib/icharger/log/file.rb', line 69

def external_temperatures?
  @rows.map(&:external_temperature?).any? { |t| t }
end

#input_voltagesObject



49
50
51
# File 'lib/icharger/log/file.rb', line 49

def input_voltages
  @rows.map(&:input_voltage)
end

#internal_temperatures(unit = :c) ⇒ Object



65
66
67
# File 'lib/icharger/log/file.rb', line 65

def internal_temperatures(unit = :c)
  @rows.each_with_object(unit).map(&:internal_temperature)
end

#internal_temperatures?Boolean



61
62
63
# File 'lib/icharger/log/file.rb', line 61

def internal_temperatures?
  @rows.map(&:internal_temperature?).any? { |t| t }
end

#millisecondsObject



41
42
43
# File 'lib/icharger/log/file.rb', line 41

def milliseconds
  @rows.map(&:time)
end

#pack_voltagesObject



53
54
55
# File 'lib/icharger/log/file.rb', line 53

def pack_voltages
  @rows.map(&:pack_voltage)
end