Class: Nuva::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/nuva/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
16
# File 'lib/nuva/repository.rb', line 7

def initialize(data)
  @count = data.count
  @all = data
  @index = {}
  data.each do |item|
    @index[item.code] = item
    @index[item.id.to_sym] = item
    @index[item.id.to_s] = item
  end
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



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

def all
  @all
end

Instance Method Details

#by_ids(ids) ⇒ Object



22
23
24
# File 'lib/nuva/repository.rb', line 22

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

#find(id_or_code) ⇒ Object



18
19
20
# File 'lib/nuva/repository.rb', line 18

def find(id_or_code)
  @index[id_or_code]
end

#inspectObject



26
27
28
# File 'lib/nuva/repository.rb', line 26

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