Class: S7::EntryCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/s7/entry_collection.rb

Overview

機密情報の集合を表現する。

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEntryCollection

Returns a new instance of EntryCollection.



11
12
13
14
# File 'lib/s7/entry_collection.rb', line 11

def initialize
  @entries = []
  @max_id = 0
end

Instance Attribute Details

#entriesObject (readonly)

機密情報の配列。



9
10
11
# File 'lib/s7/entry_collection.rb', line 9

def entries
  @entries
end

Instance Method Details

#add_entries(*entries) ⇒ Object

機密情報を追加する。



17
18
19
20
21
22
23
# File 'lib/s7/entry_collection.rb', line 17

def add_entries(*entries)
  [entries].flatten.each do |entry|
    @max_id += 1
    entry.id = @max_id
    @entries.push(entry)
  end
end

#delete_entries(*entries) ⇒ Object

機密情報を削除し、削除した機密情報を返す。



26
27
28
29
30
31
# File 'lib/s7/entry_collection.rb', line 26

def delete_entries(*entries)
  entries = [entries].flatten
  return @entries.delete_if { |entry|
    entries.include?(entry)
  }
end

#find(id) ⇒ Object

指定した id にマッチする Entry オブジェクトを entries から探す。



40
41
42
# File 'lib/s7/entry_collection.rb', line 40

def find(id)
  return @entries.find { |entry| entry.id == id }
end

#merge(other) ⇒ Object

other で指定した EntryCollection オブジェクトの entries をマージ する。



35
36
37
# File 'lib/s7/entry_collection.rb', line 35

def merge(other)
  add_entries(other.entries)
end