Sha256: 149bbd8edf49dd039447271e7f4dda0cc3e8a7f5d46a2e35c0e64b9eb72bcf59

Contents?: true

Size: 1.07 KB

Versions: 18

Compression:

Stored size: 1.07 KB

Contents

class Card
  module Set
    module Helpers
      SET_PATTERN_TEST_REGEXP = /^(?<pattern>\w+)_set\?$/

      def shortname
        first = 2 # shortname eliminates Card::Set
        last = first + num_set_parts(pattern_code)
        set_name_parts[first..last].join "::"
      end

      def underscore
        shortname.tr(":", "_").underscore
      end

      def num_set_parts pattern_code
        return 1 if pattern_code == :abstract

        Pattern.find(pattern_code).anchor_parts_count
      end

      def set_name_parts
        @set_name_parts ||= name.split "::"
      end

      def pattern_code
        @pattern_code ||= set_name_parts[2].underscore.to_sym
      end

      # handles all_set?, abstract_set?, type_set?, etc.
      def method_missing method_name, *args
        if (matches = method_name.match SET_PATTERN_TEST_REGEXP)
          pattern_code == matches[:pattern].to_sym
        else
          super
        end
      end

      def respond_to_missing? method_name, _include_private=false
        method_name.match? SET_PATTERN_TEST_REGEXP
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
card-1.103.2 lib/card/set/helpers.rb
card-1.103.1 lib/card/set/helpers.rb
card-1.103.0 lib/card/set/helpers.rb
card-1.101.7 lib/card/set/helpers.rb
card-1.102.0 lib/card/set/helpers.rb
card-1.101.6 lib/card/set/helpers.rb
card-1.101.5 lib/card/set/helpers.rb
card-1.101.4 lib/card/set/helpers.rb
card-1.101.3 lib/card/set/helpers.rb
card-1.101.2 lib/card/set/helpers.rb
card-1.101.1 lib/card/set/helpers.rb
card-1.101.0 lib/card/set/helpers.rb
card-1.100.0 lib/card/set/helpers.rb
card-1.99.6 lib/card/set/helpers.rb
card-1.99.5 lib/card/set/helpers.rb
card-1.99.4 lib/card/set/helpers.rb
card-1.99.3 lib/card/set/helpers.rb
card-1.99.2 lib/card/set/helpers.rb