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
- #channel ⇒ Object
- #duration ⇒ Object
-
#initialize(uri) ⇒ File
constructor
A new instance of File.
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
#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
#channel ⇒ Object
27 28 29 |
# File 'lib/icharger/log/file.rb', line 27 def channel @rows.first.channel end |
#duration ⇒ Object
31 32 33 |
# File 'lib/icharger/log/file.rb', line 31 def duration @rows.last.time / 10000.0 end |