Sha256: 3282855f1271f5b146db31ccef2aabc3531c81739724ea95ada03e26116c44a7

Contents?: true

Size: 994 Bytes

Versions: 1

Compression:

Stored size: 994 Bytes

Contents

module Gloomhaven
  class Character
    attr_reader :hand_size, :health_scale, :hex_color, :name, :number, :perks, :spoiler_name

    def initialize(klass)
      validate_class!(klass)
      @klass = klass
      @hand_size = data['hand_size']
      @health_scale = data['health_scale']
      @hex_color = data['hex_color']
      @name = data['name']
      @number = data['number']
      @perks = data['perks']
      @spoiler_name = data['spoiler_name'] || @name
    end

    def to_s
      @name
    end

    private

    def data
      CHARACTERS.detect { |character| character['name'].downcase == @klass.downcase }
    end

    def validate_class!(klass)
      raise ArgumentError.new("Character class must be a String") unless klass.is_a?(String)

      return if Gloomhaven::CHARACTER_NAMES.map(&:downcase).include?(klass.downcase)
        
      raise TypeError.new("Invalid klass: #{klass} is not supported. Must be one of the following: #{Gloomhaven::CHARACTER_NAMES}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gloomhaven-1.0.9.1 lib/gloomhaven/character.rb