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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dotka/storage.rb', line 5

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