Sha256: 8132567e42b978eb91c5b0280d9b77f30708df966ba8d5f1fc9f33fd7f938a09

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

module Enumerable
  #
  # Convert an array of values to a string representing it as a pig tuple
  #
  # def to_pig_tuple
  #   map{|*vals| '(' + vals.join(',') + ')' }
  # end

  #
  # Convert an array to a pig tuple
  #
  def to_pig_tuple
    '(' + self.join(',') + ')'
  end
  #
  # Convert an array of values to a string pig format
  # Delegates to to_pig_tuple -- see also to_pig_bag
  #
  def to_pig *args
    to_pig_tuple *args
  end

  #
  # Convert an array of values to a string representing it as a pig bag
  #
  # def to_pig_bag
  #   '{' + self.join(',') + '}'
  # end

  #
  # Convert and array of values to a string representing it as a pig bag
  #
  def to_pig_bag
    '{' + self.map{|*vals| vals.to_pig_tuple}.join(",") + '}'
  end

  #
  # Convert a string representing a pig bag into a nested array
  #
  def from_pig_bag
    self.split("),(").map{|t| t.gsub(/[\{\}]/, '').from_pig_tuple} rescue []
  end

  #
  # Convert a string representing a pig tuple into an array
  #
  def from_pig_tuple
    self.gsub(/[\(\)]/, '').split(',')
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wukong-1.5.4 lib/wukong/and_pig.rb
wukong-1.5.3 lib/wukong/and_pig.rb
wukong-1.5.2 lib/wukong/and_pig.rb
wukong-1.5.1 lib/wukong/and_pig.rb
wukong-1.5.0 lib/wukong/and_pig.rb
wukong-1.4.12 lib/wukong/and_pig.rb