Class: DotkaM::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/dotka/storage.rb

Instance Method Summary collapse

Instance Method Details

#get(file, conditions = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dotka/storage.rb', line 7

def get file, conditions = {}

	rows = JSON.parse File.read("#{__dir__}/../../data/#{file}.json")

	if not conditions.empty?

		rows.select! { |row|
			selected = true

			conditions.each { |key, value|
				if not (row.has_key? key) or not (row[key] == value.to_s)
					selected = false
				end
			}

			selected
		}

	end

	rows.length == 1 ? rows.first : rows

end