Module: RateCenter::Collection

Included in:
City, Lata, RateCenter
Defined in:
lib/rate_center/collection.rb

Instance Method Summary collapse

Instance Method Details

#allObject



13
14
15
# File 'lib/rate_center/collection.rb', line 13

def all
  collection
end

#collectionObject



3
4
5
6
7
# File 'lib/rate_center/collection.rb', line 3

def collection
  raise Errors::DataNotLoadedError.new("No data loaded. Load data with RateCenter.load before calling this method") if data.nil?

  @collection ||= load_collection
end

#find_by(attributes) ⇒ Object



23
24
25
26
27
# File 'lib/rate_center/collection.rb', line 23

def find_by(attributes)
  collection.find do |element|
    attributes.all? { |key, value| element[key] == value }
  end
end

#find_by!Object



29
30
31
# File 'lib/rate_center/collection.rb', line 29

def find_by!(*)
  find_by(*) || raise(Errors::NotFoundError.new)
end

#reload!Object



9
10
11
# File 'lib/rate_center/collection.rb', line 9

def reload!
  @collection = nil
end

#where(attributes) ⇒ Object



17
18
19
20
21
# File 'lib/rate_center/collection.rb', line 17

def where(attributes)
  collection.select do |element|
    attributes.all? { |key, value| element[key] == value }
  end
end