Sha256: bdeb72b0dc27696ff3af6a76ea7cd12398fbaa3eeb9ea8ed123d4315e830b349
Contents?: true
Size: 696 Bytes
Versions: 2
Compression:
Stored size: 696 Bytes
Contents
# frozen_string_literal: true module Yasd class Converter def initialize(filename) @converters = {} if filename contents = File.read(filename) instance_eval(contents) end end def call(data) data.headers.each_with_object({}) do |field, new_object| new_object[field] = convert_field(field, data[field]) new_object end end private # for DSL def convert(header, &block) @converters[header] ||= [] @converters[header] << block end def convert_field(header, value) (@converters[header] || []).reduce(value) do |_result, proc| proc.call(value) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
yasd-0.1.1 | lib/yasd/converter.rb |
yasd-0.1.0 | lib/yasd/converter.rb |