Sha256: 56b53169f34384927a9db04ddbdce218e56509b200b0fbc4c72301a0f3881dfa

Contents?: true

Size: 474 Bytes

Versions: 7

Compression:

Stored size: 474 Bytes

Contents

# frozen_string_literal: true

module Micro::Struct
  module NormalizeNames
    module AsSymbols
      REGEXP = /\A[_A-Za-z]\w*\z/.freeze
      Invalid = ->(context, val) { raise NameError.new("invalid #{context} name: #{val}") }
      AsSymbol = ->(context, val) { REGEXP =~ val ? val.to_sym : Invalid[context, val] }.curry

      def self.call(values, context:)
        Array(values).map(&AsSymbol[context])
      end
    end
  end

  private_constant :NormalizeNames
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
u-struct-1.0.0 lib/micro/struct/normalize_names.rb
u-struct-0.12.0 lib/micro/struct/normalize_names.rb
u-struct-0.11.0 lib/micro/struct/normalize_names.rb
u-struct-0.10.0 lib/micro/struct/normalize_names.rb
u-struct-0.9.0 lib/micro/struct/normalize_names.rb
u-struct-0.8.0 lib/micro/struct/normalize_names.rb
u-struct-0.7.0 lib/micro/struct/normalize_names.rb