Class: StructuraidCore::Engineering::Locations::Collection

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/structuraid_core/engineering/locations/collection.rb

Instance Method Summary collapse

Constructor Details

#initializeCollection

Returns a new instance of Collection.



7
8
9
# File 'lib/structuraid_core/engineering/locations/collection.rb', line 7

def initialize
  @locations = []
end

Instance Method Details

#add(location) ⇒ Object



15
16
17
18
19
# File 'lib/structuraid_core/engineering/locations/collection.rb', line 15

def add(location)
  raise DuplicateLabelError, location.label if find_by_label(location.label)

  locations.push(location)
end

#each(&block) ⇒ Object



11
12
13
# File 'lib/structuraid_core/engineering/locations/collection.rb', line 11

def each(&block)
  locations.each(&block)
end

#find_by_label(label) ⇒ Object



25
26
27
# File 'lib/structuraid_core/engineering/locations/collection.rb', line 25

def find_by_label(label)
  locations.find { |location| location.label == label.to_sym }
end

#find_or_add_by_label(location) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/structuraid_core/engineering/locations/collection.rb', line 37

def find_or_add_by_label(location)
  add(location)
  find_by_label(location.label)
rescue DuplicateLabelError => e
  Warning.warn(e.message)
  find_by_label(location.label)
end

#inspectObject



21
22
23
# File 'lib/structuraid_core/engineering/locations/collection.rb', line 21

def inspect
  locations.inspect
end

#lastObject



29
30
31
# File 'lib/structuraid_core/engineering/locations/collection.rb', line 29

def last
  locations.last
end

#prepend(location) ⇒ Object



33
34
35
# File 'lib/structuraid_core/engineering/locations/collection.rb', line 33

def prepend(location)
  locations.prepend(location)
end