Module: Bmg::TupleAlgebra

Defined in:
lib/bmg/support/tuple_algebra.rb

Class Method Summary collapse

Class Method Details

.allbut(tuple, butlist) ⇒ Object



4
5
6
# File 'lib/bmg/support/tuple_algebra.rb', line 4

def allbut(tuple, butlist)
  tuple.reject{|k,v| butlist.include?(k) }
end

.project(tuple, attrlist) ⇒ Object



9
10
11
# File 'lib/bmg/support/tuple_algebra.rb', line 9

def project(tuple, attrlist)
  tuple.reject{|k,v| !attrlist.include?(k) }
end

.rename(tuple, renaming) ⇒ Object



14
15
16
17
18
19
# File 'lib/bmg/support/tuple_algebra.rb', line 14

def rename(tuple, renaming)
  tuple.each_with_object({}){|(k,v),m|
    m[renaming[k] || k] = v
    m
  }
end

.symbolize_keys(h) ⇒ Object



22
23
24
25
# File 'lib/bmg/support/tuple_algebra.rb', line 22

def symbolize_keys(h)
  return h if h.empty?
  h.each_with_object({}){|(k,v),h| h[k.to_sym] = v }
end