Sha256: 1fe49e91d2c38ef7a5600b8975edd134a3cc0219ecf1ed3f94de094893ecfc35

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

class MonsterIndex::Monster
  attr_accessor :name, :size_type, :hit_dice, :initiative, :speed, :ac, :attack, :alignment, :url

  @@all = []

  def initialize(monster_hash = {})
    monster_hash.each {|key, value| self.send(("#{key}="), value)}
    @@all << self
  end

  def self.create_from_collection(monster_array)
    monster_array.each do |monster_hash|
      self.new(monster_hash)
    end
  end

  def add_monster_attributes(attributes_hash)
    attributes_hash.each {|key, value| self.send(("#{key}="), value)}
    self
  end

  def self.get_names
    names = []
    @@all.each do |monster|
      names << monster.name
    end
    names
  end

  def self.list
    @@all.each do |monster|
      puts "#{monster.name}"
    end
    puts
  end

  def self.list_some(letter)
    @@all.each do |monster|
      if monster.name.downcase.match(/\A[#{letter.downcase}]/)
        puts "#{monster.name}"
      end
    end
    puts
  end

  def self.view_profile(name)
    monster = @@all.find {|one| one.name == name}
    puts "Size/Type: #{monster.size_type}"
    puts "Hit Dice: #{monster.hit_dice}"
    puts "Initiative: #{monster.initiative}"
    puts "Speed: #{monster.speed}"
    puts "AC: #{monster.ac}"
    puts "Attack: #{monster.attack}"
    puts "Alignment: #{monster.alignment}"
    puts "More info at: #{monster.url}"
    puts
  end

  def self.get_monster(name)
    @@all.find {|one| one.name == name}
  end

  def self.all
    @@all
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
monster_index-0.1.1 lib/monster_index/monster.rb