Class: StructuraidCore::Engineering::Locations::Collection
- Includes:
- Enumerable
- Defined in:
- lib/structuraid_core/engineering/locations/collection.rb
Instance Method Summary collapse
- #add(location) ⇒ Object
- #each(&block) ⇒ Object
- #find_by_label(label) ⇒ Object
- #find_or_add_by_label(location) ⇒ Object
-
#initialize ⇒ Collection
constructor
A new instance of Collection.
- #inspect ⇒ Object
- #last ⇒ Object
- #prepend(location) ⇒ Object
Constructor Details
#initialize ⇒ Collection
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.) find_by_label(location.label) end |
#inspect ⇒ Object
21 22 23 |
# File 'lib/structuraid_core/engineering/locations/collection.rb', line 21 def inspect locations.inspect end |
#last ⇒ Object
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 |