Class: GamesAndRpgParadise::Mud::Character

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/mud/character/character.rb

Overview

RpgParadise::Mud::Character

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ Character

#

initialize

#


32
33
34
35
36
37
38
39
40
41
# File 'lib/games_and_rpg_paradise/mud/character/character.rb', line 32

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  # set_commandline_arguments(
  #   commandline_arguments
  # )
  run if run_already
end

Instance Attribute Details

#ageObject Also known as: age?

Returns the value of attribute age.



26
27
28
# File 'lib/games_and_rpg_paradise/mud/character/character.rb', line 26

def age
  @age
end

#character_nameObject Also known as: character_name?, name?, name

Returns the value of attribute character_name.



20
21
22
# File 'lib/games_and_rpg_paradise/mud/character/character.rb', line 20

def character_name
  @character_name
end

#genderObject Also known as: gender?

Returns the value of attribute gender.



24
25
26
# File 'lib/games_and_rpg_paradise/mud/character/character.rb', line 24

def gender
  @gender
end

Class Method Details

.[](i = '') ⇒ Object

#

GamesAndRpgParadise::Mud::Characters[]

#


108
109
110
# File 'lib/games_and_rpg_paradise/mud/character/character.rb', line 108

def self.[](i = '')
  new(i)
end

.load(file_or_hash) ⇒ Object

#

GamesAndRpgParadise::Mud::Character.load

This method expects a hash such as:

{:character_name=>"shevy", :gender=>"male", :age=>"33"}

Alternatively, it accepts a yaml .yml file.

#


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/games_and_rpg_paradise/mud/character/character.rb', line 76

def self.load(file_or_hash)
  if file_or_hash.is_a? Array # iterate through them
    file_or_hash.each {|entry|
      Mud::Character.load(entry)
    }
  else
    if file_or_hash.is_a? Hash
      _ = Character.new
      if file_or_hash.has_key? :character_name
        _.character_name = file_or_hash.delete(:character_name)
      end
      if file_or_hash.has_key? :gender
        _.gender = file_or_hash.delete(:gender)
      end
      if file_or_hash.has_key? :age
        _.age = file_or_hash.delete(:age)
      end
      return _
    else
      if file_or_hash.include? '.yml' # We assume a yaml file here.
        # If we provide a .yml file then we will call ourself again.
        return Character.load(YAML.load_file(file_or_hash))
      else
        raise 'Please provide a yaml .yml file.'
      end
    end
  end
end

Instance Method Details

#resetObject

#

reset (reset tag)

#


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/games_and_rpg_paradise/mud/character/character.rb', line 46

def reset
  # ======================================================================= #
  # === @character_name
  # ======================================================================= #
  @character_name = ''
  # ======================================================================= #
  # === @gender
  # ======================================================================= #
  @gender = ''
  # ======================================================================= #
  # === @age
  # ======================================================================= #
  @age = ''
end

#runObject

#

run (run tag)

#


64
65
# File 'lib/games_and_rpg_paradise/mud/character/character.rb', line 64

def run
end