Class: Neoneo::SingleSelectArray
- Inherits:
-
Array
- Object
- Array
- Neoneo::SingleSelectArray
- Defined in:
- lib/neoneo.rb
Overview
Normal array with a few select extensions
Instance Method Summary collapse
-
#find(name) ⇒ Object
Find an item in the array by it’s name.
-
#find_or_use(value) ⇒ Object
Find an item in the array by it’s name when value is a string.
Instance Method Details
#find(name) ⇒ Object
Find an item in the array by it’s name
49 50 51 |
# File 'lib/neoneo.rb', line 49 def find(name) self.select {|item| item.name == name}.first end |
#find_or_use(value) ⇒ Object
Find an item in the array by it’s name when value is a string. If the passed value is a Member or Category object just return that and if none of those rules apply return nil.
This method allows the user e.g. to assign new task by just using the name of the project member and not it’s corresponding Member object.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/neoneo.rb', line 59 def find_or_use(value) case value when String result = find(value) when Member, Category, Project result = value else result = nil end result end |