Class: Medcon::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/medcon/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Repository

Returns a new instance of Repository.



7
8
9
10
11
12
13
14
15
# File 'lib/medcon/repository.rb', line 7

def initialize(data)
  @all = data
  @index = {}
  data.each do |item|
    index_keys(item).each do |key|
      @index[normalize_key(key)] = item
    end
  end
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



5
6
7
# File 'lib/medcon/repository.rb', line 5

def all
  @all
end

Instance Method Details

#by_ids(ids) ⇒ Object



21
22
23
# File 'lib/medcon/repository.rb', line 21

def by_ids(ids)
  ids.map { |x| find x }.compact
end

#find(id) ⇒ Object



17
18
19
# File 'lib/medcon/repository.rb', line 17

def find(id)
  @index[normalize_key(id)]
end

#inspectObject



25
26
27
# File 'lib/medcon/repository.rb', line 25

def inspect
  "#<#{self.class} count=#{all.count}>"
end