Class: Tcxxxer::DB

Inherits:
Object
  • Object
show all
Defined in:
lib/tcxxxer/db.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ DB

Returns a new instance of DB.



22
23
24
# File 'lib/tcxxxer/db.rb', line 22

def initialize(file)
  @file_name = file
end

Class Method Details

.file_type(file_name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/tcxxxer/db.rb', line 3

def self.file_type(file_name)
  case File.extname(file_name).downcase
  when '.tcx'
    TCX
  when '.gpx'
    GPX
  when '.fit'
    FIT
  else
    raise "Unknown filetype"
  end
end

.open(file_name) ⇒ Object



16
17
18
19
20
# File 'lib/tcxxxer/db.rb', line 16

def self.open(file_name)
  db = new(file_name)
  db.parse
  return db
end

Instance Method Details

#course(course_id) ⇒ Object



41
42
43
# File 'lib/tcxxxer/db.rb', line 41

def course(course_id)
  @doc.courses(course_id)
end

#coursesObject



37
38
39
# File 'lib/tcxxxer/db.rb', line 37

def courses
  @doc.courses
end

#parseObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/tcxxxer/db.rb', line 26

def parse 
  case self.class.file_type(@file_name)
  when TCX
    @doc = Tcxxxer::TcxParser.open(@file_name)
  when GPX
    @doc = Tcxxxer::GpxParser.open(@file_name)
  when FIT
    @doc = Tcxxxer::FitParser.open(@file_name)
  end
end