Sha256: 1338c702fbbaf8d9c2405e0eadf9450e8860ed78c36bf7b5d7a4a4fffb1b935d

Contents?: true

Size: 685 Bytes

Versions: 3

Compression:

Stored size: 685 Bytes

Contents

# frozen_string_literal: true

module Physical
  module PropertyReaders
    private

    NORMALIZED_METHOD_REGEX = /(\w+)\??$/.freeze

    def method_missing(method)
      symbolized_properties = properties.symbolize_keys
      method_name = normalize_method_name(method)
      if symbolized_properties.key?(method_name)
        symbolized_properties[method_name]
      else
        super
      end
    end

    def respond_to_missing?(method, *args)
      method_name = normalize_method_name(method)
      properties.symbolize_keys.key?(method_name) || super
    end

    def normalize_method_name(method)
      method.to_s.sub(NORMALIZED_METHOD_REGEX, '\1').to_sym
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
physical-0.5.1 lib/physical/property_readers.rb
physical-0.5.0 lib/physical/property_readers.rb
physical-0.4.9 lib/physical/property_readers.rb