Class: Alf::Types::Renaming

Inherits:
Object
  • Object
show all
Defined in:
lib/alf/types/renaming.rb

Overview

Encapsulates a Renaming information

Instance Method Summary collapse

Instance Method Details

#complete(attr_list) ⇒ Object

Returns a completed renaming with at least all attributes in `attr_list`


23
24
25
# File 'lib/alf/types/renaming.rb', line 23

def complete(attr_list)
  Renaming.new attr_list.to_a.each_with_object(reused_instance.dup){|k,h| h[k] ||= k}
end

#rename_attr_list(attr_list) ⇒ AttrList

Renames an attribute list.

Parameters:

Returns:

  • (AttrList)

    the input list where attributes have been renamed


42
43
44
# File 'lib/alf/types/renaming.rb', line 42

def rename_attr_list(attr_list)
  AttrList.coerce(attr_list).map{|k| self[k] || k}
end

#rename_tuple(tuple) ⇒ Hash

Renames a tuple according to this renaming pairs.

The tuple should have all attributes defined in this renaming. Strange results may appear otherwise.

Parameters:

  • tuple (Hash)

    a tuple to rename

Returns:

  • (Hash)

    the renamed tuple


34
35
36
# File 'lib/alf/types/renaming.rb', line 34

def rename_tuple(tuple)
  Hash[tuple.map{|k,v| [self[k] || k, v]}]
end

#to_attr_listObject

Returns an attribute list with renaming keys


59
60
61
# File 'lib/alf/types/renaming.rb', line 59

def to_attr_list
  AttrList.new reused_instance.keys
end

#to_lispyString

Returns a lispy expression.

Returns:

  • (String)

    a lispy expression for this renaming


54
55
56
# File 'lib/alf/types/renaming.rb', line 54

def to_lispy
  Support.to_ruby_literal(to_hash)
end

#to_renamingObject

Returns self


47
48
49
# File 'lib/alf/types/renaming.rb', line 47

def to_renaming
  self
end

#to_ruby_literalString Also known as: inspect, to_s

Returns a ruby literal for this renaming.

Returns:

  • (String)

    a literal s.t. `eval(self.to_ruby_literal) == self`


66
67
68
# File 'lib/alf/types/renaming.rb', line 66

def to_ruby_literal
  "Alf::Renaming[#{Support.to_ruby_literal(reused_instance)}]"
end