Lassie Posted February 22, 2017 Share Posted February 22, 2017 I want to convert a program from what I think is Ruby to PHP as I have no knowledge of Ruby. Could someone confirm if the posted code is Ruby please and if there are any known methods to help with a conversion. Is it possible to run Ruby code within PHP? The background to this request is that I have a 3 axis accelerometer and would like to construct a pedometer. I have the data logged to a file but coding the pedometer is a challenge. I found the following ,A Pedometer in the Real World Dessy Daskalov' which does what I want but I dont follow the code. For those interested a link to the article:-http://www.aosabook.org/en/500L/a-pedometer-in-the-real-world.html Any guidance appreciated and I hope this is the right forum. class Parser attr_reader :parsed_data def self.run(data) parser = Parser.new(data) parser.parse parser end def initialize(data) @data = data end def parse @parsed_data = @data.to_s.split(';').map { |x| x.split('|') } .map { |x| x.map { |x| x.split(',').map(&:to_f) } } unless @parsed_data.map { |x| x.map(&:length).uniq }.uniq == [[3]] raise 'Bad Input. Ensure data is properly formatted.' end if @parsed_data.first.count == 1 filtered_accl = @parsed_data.map(&:flatten).transpose.map do |total_accl| grav = Filter.low_0_hz(total_accl) user = total_accl.zip(grav).map { |a, b| a - b } [user, grav] end @parsed_data = @parsed_data.length.times.map do |i| user = filtered_accl.map(&:first).map { |elem| elem[i] } grav = filtered_accl.map(&:last).map { |elem| elem[i] } [user, grav] end end end end Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 23, 2017 Share Posted February 23, 2017 Yes, this is Ruby. No, you cannot run Ruby within PHP, and there's no way to automatically translate one language into another. I see two possibilities: You try to understand the concept and then write your own PHP implementation from scratch. You pay somebody to do a manual translation. This will be expensive. There aren't many programmers who are proficient in both Ruby and PHP, and the job is tedious rather than challenging. Quote Link to comment Share on other sites More sharing options...
Lassie Posted February 23, 2017 Author Share Posted February 23, 2017 Thanks for confirming that. Being a pensioner, your first option is the way i will go. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.