...
 
Commits (2)
......@@ -2,34 +2,34 @@ require "csv"
require "./cycling/**"
module Cycling
VERSION = "0.2.1"
VERSION = "0.3.1"
# Initializing
Cycling::Options
ENV["file"] ||= "./data.csv"
# Create a new file if once doesn't exist
def self.create_file()
def self.create_file
File.touch(ENV["file"]) # Create new file
# Create Header Row
first_row = CSV.build do |csv|
csv.row "Date",
"Distance",
"Time",
"Average Speed",
"Maximum Speed",
"Average Heart Rate",
"Cadence",
"Comments"
"Distance",
"Time",
"Average Speed",
"Maximum Speed",
"Average Heart Rate",
"Cadence",
"Comments"
end
File.write(ENV["file"], first_row) # Write to file
end
# Check if data file exist or create it
File.exists?(ENV["file"]) ? true : Cycling.create_file()
File.exists?(ENV["file"]) ? true : Cycling.create_file
# Create new row of test data
def self.build_file()
def self.build_file
# Prompt user for info
puts "Enter your ride details..."
puts "Fields are optional, just press ENTER to skip"
......@@ -59,12 +59,13 @@ module Cycling
d8 = d8.empty? ? nil : d8.chomp
# Build CSV Row
result = CSV.build do |csv|
csv.row d1,d2,d3,d4,d5,d6,d7,d8
csv.row d1, d2, d3, d4, d5, d6, d7, d8
end
# Write data to file
File.write(ENV["file"], result, mode: "a")
end
Cycling.build_file()
Cycling.build_file
# Some Text to know it all worked.
puts "Success: Data written to #{ENV["file"]}."
end
require "xml"
class Cycling::AAT
def self.import(file)
f = File.read(file)
d = XML.parse(f).children
# Get Time
d.each do |q|
puts q.children[1].inner_text
end
# Get Entries
d.each{|q| q.children[3].children.each{|f| f.children.each do |g|
puts g # Get attributes for lat and lon
g.children.each{|h| puts h.children} # Printing for testing purposes
# TODO: Format the data to nested array or some other type to access
end}}
end
def self.error
puts "There was an error paring the file, please make sure your AAT gpx file is correct..."
exit
end
end
require "option_parser"
require "../cycling"
require "./options"
class Cycling::Options
# Option Flags to select different options for things
......@@ -9,17 +10,27 @@ class Cycling::Options
puts "Not Available"
exit
end
# Specifiy the file you wish to save data to as opposed to data.csv
p.on("-f PATH", "--file PATH", "Choose file to write to") do |new_path|
ENV["file"] = new_path.empty? ? "data.csv" : new_path
end
p.on("-a", "--aat", "Put path to AAT data file to input") do
puts "Not Available"
# For importing AAT GPX file
p.on("-a FILE", "--aat FILE", "Put path to AAT data file to input") do |aat_file|
# if aat_file.empty?
# raise "File Needs to be specified... Please try again..."
# end
File.exists?(aat_file) ? Cycling::AAT.import(aat_file) : Cycling::AAT.error
exit
end
# Get help for this program
p.on("-h", "--help", "Show this help") do
puts p
exit
end
# If flag unknown show help but show error
p.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
......