Class: Tmx::Objects

Inherits:
Array
  • Object
show all
Defined in:
lib/tmx/objects.rb

Overview

Objects is a thin wrapper around an array of Object.

Instance Method Summary collapse

Instance Method Details

#find(params) ⇒ Object

Allows finding by type or a specfied hash of parameters

Examples:

Find all objects that have the type ‘ground’


objects.find(:floor)
objects.find(type: 'floor')

Find all objects that have the name ‘mushroom’


objects.find(name: "mushroom")


20
21
22
23
24
25
26
27
28
# File 'lib/tmx/objects.rb', line 20

def find(params)
  params = { type: params } if params.is_a?(String)

  found_objects = find_all do |object|
    params.any? {|key,value| object.send(key) == value.to_s }
  end.compact

  self.class.new found_objects
end