Sha256: defdb0614e65e8346c3581a18b81923ff0aa32a8d089045a286e6a207d89abbd
Contents?: true
Size: 1.67 KB
Versions: 1
Compression:
Stored size: 1.67 KB
Contents
#-- # Copyright (c) 2016-2016, John Mettraux, jmettraux@gmail.com # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # Made in Japan. #++ module Tafel VERSION = '0.1.0' def self.turn(data) data = to_array(data) if data.all? { |row| row.is_a?(Array) } data elsif data.all? { |row| row.is_a?(Hash) } turn_array_of_hashes(data) else nil end end protected def self.to_array(data) data #return data.values if data.is_a?(Hash) #return Array[data] end def self.turn_array_of_hashes(data) keys = data.inject([]) { |a, row| a.concat(row.keys) }.uniq [ keys ] + data.collect { |row| keys.collect { |k| row[k] } } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tafel-0.1.0 | lib/tafel.rb |