Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/bjn_inventory/array.rb

Overview

Inventory array helper

Direct Known Subclasses

BjnInventory::List

Instance Method Summary collapse

Instance Method Details

#bykey(key) ⇒ Object



15
16
17
# File 'lib/bjn_inventory/array.rb', line 15

def bykey(key)
    find_key 'key', key
end

#byname(name) ⇒ Object



19
20
21
# File 'lib/bjn_inventory/array.rb', line 19

def byname(name)
    find_key 'name', name
end

#find_key(key, value) ⇒ Object

This array is treated as a list of hashes, with certain command key or name fields that you can search by.



7
8
9
10
11
12
13
# File 'lib/bjn_inventory/array.rb', line 7

def find_key(key, value)
    keys = [key, key.upcase, key.downcase, key.capitalize]
    keys.concat(keys.map &:intern)
    self.find do |hash|
        keys.any? { |key| hash[key] == value }
    end
end