Class: Pyper::Pipes::FieldRename
- Inherits:
-
Struct
- Object
- Struct
- Pyper::Pipes::FieldRename
- Defined in:
- lib/pyper/pipes/field_rename.rb
Overview
Instance Attribute Summary collapse
-
#attr_map ⇒ Object
Returns the value of attribute attr_map.
Instance Method Summary collapse
-
#pipe(attrs_or_items, status = {}) ⇒ Hash|Enumerator<Hash>
The item(s) with fields renamed.
- #rename(item) ⇒ Object
Instance Attribute Details
#attr_map ⇒ Object
Returns the value of attribute attr_map
3 4 5 |
# File 'lib/pyper/pipes/field_rename.rb', line 3 def attr_map @attr_map end |
Instance Method Details
#pipe(attrs_or_items, status = {}) ⇒ Hash|Enumerator<Hash>
Returns The item(s) with fields renamed.
8 9 10 11 12 13 |
# File 'lib/pyper/pipes/field_rename.rb', line 8 def pipe(attrs_or_items, status = {}) case attrs_or_items when Hash then rename(attrs_or_items) else attrs_or_items.map { |item| rename(item) } end end |
#rename(item) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/pyper/pipes/field_rename.rb', line 15 def rename(item) attr_map.each do |old,new| item[new.to_sym] = item.delete(old.to_sym) if item.has_key?(old.to_sym) item[new.to_s] = item.delete(old.to_s) if item.has_key?(old.to_s) end item end |