Class: OpenTx::Log::File
- Inherits:
-
Object
- Object
- OpenTx::Log::File
- Defined in:
- lib/opentx/log/file.rb
Instance Attribute Summary collapse
-
#sessions ⇒ Array<Session>
readonly
Sessions contained in this file.
Class Method Summary collapse
-
.opentx?(uri) ⇒ OpenTx::Log::File
Determines if the file at the given URI is an OpenTx log file.
Instance Method Summary collapse
-
#duration ⇒ Float
Gets the total duration of all sessions contained within.
-
#initialize(uri) ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize(uri) ⇒ File
Returns a new instance of File.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/opentx/log/file.rb', line 20 def initialize uri @sessions = [] open(uri, 'r') do |file| session = CSV.new(file, headers: true).map { |csv| csv } # a little sanity checking raise 'No session data found' if session.empty? raise 'Unknown column layout' unless Session.known_rows?(session.first.headers) @sessions << Session.new(session) end rescue => e raise ArgumentError, "File does not appear to be an OpenTx log (#{e})" end |
Instance Attribute Details
#sessions ⇒ Array<Session> (readonly)
Returns Sessions contained in this file.
10 11 12 |
# File 'lib/opentx/log/file.rb', line 10 def sessions @sessions end |
Class Method Details
.opentx?(uri) ⇒ OpenTx::Log::File
Determines if the file at the given URI is an OpenTx log file.
16 17 18 |
# File 'lib/opentx/log/file.rb', line 16 def self.opentx? uri File.new(uri) rescue nil end |
Instance Method Details
#duration ⇒ Float
Gets the total duration of all sessions contained within.
39 40 41 |
# File 'lib/opentx/log/file.rb', line 39 def duration @sessions.map(&:duration).reduce(&:+) end |