Class: HashTransformer
- Inherits:
-
Object
- Object
- HashTransformer
- Defined in:
- lib/ascii_invoicer/hash_transformer.rb
Instance Attribute Summary collapse
-
#new_hash ⇒ Object
readonly
Returns the value of attribute new_hash.
-
#original_hash ⇒ Object
readonly
Returns the value of attribute original_hash.
-
#rules ⇒ Object
writeonly
Sets the attribute rules.
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ HashTransformer
constructor
A new instance of HashTransformer.
- #transform ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ HashTransformer
Returns a new instance of HashTransformer.
7 8 9 10 11 12 13 |
# File 'lib/ascii_invoicer/hash_transformer.rb', line 7 def initialize(hash = {}) @original_hash = hash[:original_hash] @original_hash ||= {} @new_hash = {} @rules = hash[:rules] @rules ||= [] end |
Instance Attribute Details
#new_hash ⇒ Object (readonly)
Returns the value of attribute new_hash.
4 5 6 |
# File 'lib/ascii_invoicer/hash_transformer.rb', line 4 def new_hash @new_hash end |
#original_hash ⇒ Object (readonly)
Returns the value of attribute original_hash.
4 5 6 |
# File 'lib/ascii_invoicer/hash_transformer.rb', line 4 def original_hash @original_hash end |
#rules=(value) ⇒ Object (writeonly)
Sets the attribute rules
5 6 7 |
# File 'lib/ascii_invoicer/hash_transformer.rb', line 5 def rules=(value) @rules = value end |
Instance Method Details
#transform ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/ascii_invoicer/hash_transformer.rb', line 15 def transform @new_hash = @original_hash @rules.each {|rule| @new_hash.set_path(rule[:new], @original_hash.get_path(rule[:old])) } return @new_hash end |