diff options
| author | Robert | 2017-09-29 18:23:56 +0200 |
|---|---|---|
| committer | Robert | 2017-10-02 10:52:07 +0200 |
| commit | 1bc4ab6684803a3974bd65f6531bd43a57c15fd0 (patch) | |
| tree | bc30e8698ada3f660633adbd28e88083f39896a6 /spec/support/data_modifier | |
| parent | f034dc2999a56295178c64921e6f059adc1a7bd9 (diff) | |
| download | chouette-core-1bc4ab6684803a3974bd65f6531bd43a57c15fd0.tar.bz2 | |
Refs: #4627@2h;
Comprehensive Tests for ComplianceControl Class Level Default Attributes
Diffstat (limited to 'spec/support/data_modifier')
| -rw-r--r-- | spec/support/data_modifier/box.rb | 5 | ||||
| -rw-r--r-- | spec/support/data_modifier/hash.rb | 16 |
2 files changed, 18 insertions, 3 deletions
diff --git a/spec/support/data_modifier/box.rb b/spec/support/data_modifier/box.rb index 0fb95f743..0847b628c 100644 --- a/spec/support/data_modifier/box.rb +++ b/spec/support/data_modifier/box.rb @@ -1,3 +1,4 @@ +require_relative 'hash' module Support module DataModifier module Box @@ -7,9 +8,7 @@ module Support class << self def unbox atts - atts.inject Hash.new do | h, (k,v) | - h.merge(k => value_of(v)) - end + Hash.map_values(atts, method(:value_of)) end def value_of v self === v ? v.value : v diff --git a/spec/support/data_modifier/hash.rb b/spec/support/data_modifier/hash.rb new file mode 100644 index 000000000..05da3cf4f --- /dev/null +++ b/spec/support/data_modifier/hash.rb @@ -0,0 +1,16 @@ +module Support + module DataModifier + module Hash extend self + def map_values hashy, f=nil, &fn + raise ArgumentError, "need block or function arg" unless f = fn || f + hashy.inject({}){ |h, (k,v)| h.merge(k => f.(v)) } + end + def first_values ary_hash + map_values(ary_hash, &:first) + end + def last_values ary_hash + map_values(ary_hash, &:last) + end + end + end +end |
