Class: ICharger::Log::File
- Inherits:
-
Object
- Object
- ICharger::Log::File
- Defined in:
- lib/icharger/log/file.rb
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Class Method Summary collapse
-
.icharger?(uri) ⇒ ICharger::Log::File
Determines if the file at the given URI is an iCharger log file.
Instance Method Summary collapse
- #capacities ⇒ Object
- #cell_count ⇒ Object
- #cell_voltages(index) ⇒ Object
-
#channel ⇒ Number
Gets the charger channel number.
- #currents ⇒ Object
-
#duration ⇒ Float
Gets the duration of the log, in seconds.
- #external_temperatures(unit = :c) ⇒ Object
- #external_temperatures? ⇒ Boolean
-
#initialize(uri) ⇒ File
constructor
A new instance of File.
- #input_voltages ⇒ Object
- #internal_temperatures(unit = :c) ⇒ Object
- #internal_temperatures? ⇒ Boolean
- #milliseconds ⇒ Object
- #pack_voltages ⇒ Object
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
#rows ⇒ Object (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
#capacities ⇒ Object
57 58 59 |
# File 'lib/icharger/log/file.rb', line 57 def capacities @rows.map(&:capacity) end |
#cell_count ⇒ Object
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 |
#channel ⇒ Number
Gets the charger channel number.
30 31 32 |
# File 'lib/icharger/log/file.rb', line 30 def channel @rows.first.channel end |
#currents ⇒ Object
45 46 47 |
# File 'lib/icharger/log/file.rb', line 45 def currents @rows.map(&:current) end |
#duration ⇒ Float
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_voltages ⇒ Object
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 |
#milliseconds ⇒ Object
41 42 43 |
# File 'lib/icharger/log/file.rb', line 41 def milliseconds @rows.map(&:time) end |
#pack_voltages ⇒ Object
53 54 55 |
# File 'lib/icharger/log/file.rb', line 53 def pack_voltages @rows.map(&:pack_voltage) end |