class OpenTx::Log::File

Attributes

sessions[R]

@return [Array<Session>] Sessions contained in this file

Public Class Methods

new(uri) click to toggle source
# 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
opentx?(uri) click to toggle source

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

@param uri URI to file to read @return [OpenTx::Log::File] loaded file if the file is an OpenTx log file, nil otherwise

# File lib/opentx/log/file.rb, line 16
def self.opentx? uri
  File.new(uri) rescue nil
end

Public Instance Methods

duration() click to toggle source

Gets the total duration of all sessions contained within.

@return [Float] total duration of all sessions, in seconds

# File lib/opentx/log/file.rb, line 39
def duration
  @sessions.map(&:duration).reduce(&:+)
end