Class: HTransform
- Inherits:
-
Object
- Object
- HTransform
- Defined in:
- lib/htransform.rb,
lib/htransform/version.rb
Constant Summary collapse
- ValueNotPresentError =
Class.new(StandardError)
- VERSION =
"0.9.0"
Class Attribute Summary collapse
-
.input_nest ⇒ Object
readonly
Returns the value of attribute input_nest.
-
.output_nest ⇒ Object
readonly
Returns the value of attribute output_nest.
-
.transform_block ⇒ Object
readonly
Returns the value of attribute transform_block.
Class Method Summary collapse
Instance Method Summary collapse
- #convert(input) ⇒ Object
-
#initialize ⇒ HTransform
constructor
A new instance of HTransform.
Constructor Details
#initialize ⇒ HTransform
Returns a new instance of HTransform.
23 24 25 26 27 28 |
# File 'lib/htransform.rb', line 23 def initialize @output_hash = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) } @input_nest = [] @output_nest = [] @inputs = Set.new end |
Class Attribute Details
.input_nest ⇒ Object (readonly)
Returns the value of attribute input_nest.
10 11 12 |
# File 'lib/htransform.rb', line 10 def input_nest @input_nest end |
.output_nest ⇒ Object (readonly)
Returns the value of attribute output_nest.
11 12 13 |
# File 'lib/htransform.rb', line 11 def output_nest @output_nest end |
.transform_block ⇒ Object (readonly)
Returns the value of attribute transform_block.
8 9 10 |
# File 'lib/htransform.rb', line 8 def transform_block @transform_block end |
Class Method Details
.convert(input_hash) ⇒ Object
13 14 15 |
# File 'lib/htransform.rb', line 13 def convert(input_hash) new.convert(input_hash) end |
.transform(&trans_block) ⇒ Object
17 18 19 |
# File 'lib/htransform.rb', line 17 def transform(&trans_block) @transform_block = trans_block end |
Instance Method Details
#convert(input) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/htransform.rb', line 30 def convert(input) unless input.is_a? Hash if input.respond_to? :to_hash input = input.to_hash else raise ArgumentError "object is not a Hash or does not respond to to_hash" end end @input_hash = input instance_exec(&self.class.transform_block) Hash[@output_hash] end |