Created
June 17, 2016 13:26
-
-
Save Dysp/574320db19b811233a1144fba151dbea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubyXL' | |
# This is a class. It does a lot of things on which I will elaborate later. | |
class Kincom | |
def initialize(file, name) | |
@filename = find_filename(file) | |
@subject = name | |
# Returns object with sheets | |
xlsx_sheets = load(file) | |
# Returns an array with arrays of raw data for each kick | |
extract_values(xlsx_sheets) | |
end | |
def load(file) | |
book = RubyXL::Parser.parse(file) | |
book.worksheets | |
end | |
def extract_values(sheets) | |
array = [] | |
sheets.each do |sheet| | |
array << sheet.map { |row| row[1].value.to_f } | |
end | |
array | |
end | |
def find_filename(file) | |
File.basename(file) | |
end | |
def calculate | |
each do |a| | |
if positive?(a) == true | |
right_kick = true | |
normalize(self, right_kick) | |
elsif positive?(a) == false | |
right_kick = false | |
normalize(self, right_kick) | |
else | |
puts 'Fejl.' | |
end | |
end | |
return { right: right_array, left: left_array } | |
end | |
def positive?(array) | |
return true if array.inject(:+).quo(array.size) > 0 | |
end | |
def normalize(array, right_kick) | |
array.reverse! | |
volt = array.drop(array.length / 3) | |
volt.reverse! | |
if right_kick == true | |
volt.map! { |x| x + array.min.abs } | |
elsif right_kick == false | |
volt.map! { |x| (x - array.max.abs) * -1 } | |
else | |
puts 'lol' | |
end | |
end | |
end | |
puts 'tester..' | |
test = Kincom.new('test.xlsx', 'Lol') | |
test.calculate | |
p test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment