Sha256: 3431765752de2f518f1a960e92ba9a088d0c8b1d7282d0569fb8041e42a2504e
Contents?: true
Size: 1.1 KB
Versions: 5
Compression:
Stored size: 1.1 KB
Contents
module Csv2hash module Coercers class YamlCoercer < Struct.new(:rules) def deserialize! deserialize_validator! deserialize_regex! deserialize_range! end private def deserialize_validator! begin extra_validator = self.rules.fetch(:extra_validator) self.rules[:extra_validator] = eval("::#{extra_validator}").new rescue KeyError # Rules without ExtraValidator rescue SyntaxError # When extra validator is a instance of Object end end def deserialize_regex! y, x = self.rules.fetch :position if y.is_a?(Array) column, matcher_string = y self.rules[:position] = [[column, Regexp.new(matcher_string)],x] end end def deserialize_range! begin values = self.rules.fetch(:values) if values.is_a?(String) match_data = values.match(/^\((?<range>.*)\)$/) self.rules[:values] = eval(match_data[:range]) end rescue KeyError # Rules without ExtraValidator end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems