Module: World

Defined in:
lib/tools/world.rb

Defined Under Namespace

Classes: WorldObject

Class Method Summary collapse

Class Method Details

.add(being) ⇒ Object



23
24
25
# File 'lib/tools/world.rb', line 23

def self.add(being)
  @objects.push(being)
end

.find_name(name) ⇒ Object



33
34
35
36
37
# File 'lib/tools/world.rb', line 33

def self.find_name(name)
  @objects.each do |being|
    return being if being.name == name
  end
end

.find_tag(tag) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/tools/world.rb', line 39

def self.find_tag(tag)
  beings = []
  @objects.each do |being|
    beings.push(being) if being.tags.include?(tag)
  end
  return beings
end

.find_tags(tags) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tools/world.rb', line 47

def self.find_tags(tags)
  return @objects if tags.empty?
  beings = []
  return @objects if tags.empty?
  @objects.each do |being|
    new = tags.clone
    new.delete_if { |t| being.tags.include?(t) }
    beings.push(being) if new.empty?
  end
  return beings
end

.setup(beings) ⇒ Object



27
28
29
30
31
# File 'lib/tools/world.rb', line 27

def self.setup(beings)
  beings.each do |ary|
    add(WorldObject.new(ary[0], ary[1], ary[2]))
  end
end