Sha256: 67839a00fbade57b1f149a9ca3e9257f92b666d14f39bc59b742e87670f1529c
Contents?: true
Size: 1.29 KB
Versions: 46
Compression:
Stored size: 1.29 KB
Contents
module Eco module Data class Mapper # it expects [[v1a, v1b], [v2a, v2b] ...] def initialize (array_of_arrays = [], internal: :last) @source = array_of_arrays if @source # internal should be always last in @source @source = @source.map { |a| a.reverse } unless internal == :last # first declarations take priority @by_external = @source.reverse.to_h @by_internal = @source.reverse.map do |pair| pair.reverse end.to_h end end def list(type = :internal) return [] if !@source @source.map do |pair| type == :internal ? pair.last : pair.first end.uniq end def internal?(value) return true if !@source @by_internal.key?(value) end def external?(value) return true if !@source @by_external.key?(value) end def include?(value) return true if !@source internal?(value) || external?(value) end def to_internal(value) return value if !@source @by_external[value] end def to_external(value) return value if !@source @by_internal[value] end end end end
Version data entries
46 entries across 46 versions & 1 rubygems