Class: Meibo::DataSet
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/meibo/data_set.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data, roster:) ⇒ DataSet
Returns a new instance of DataSet.
9
10
11
12
13
|
# File 'lib/meibo/data_set.rb', line 9
def initialize(data, roster:)
@data = data
@roster = roster
@cache = {}
end
|
Instance Attribute Details
#roster ⇒ Object
Returns the value of attribute roster.
7
8
9
|
# File 'lib/meibo/data_set.rb', line 7
def roster
@roster
end
|
Instance Method Details
#<<(new_data) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/meibo/data_set.rb', line 15
def <<(new_data)
raise DataNotFoundError, "sourcedIdがありません" unless new_data.sourced_id
raise SourcedIdDuplicatedError, "sourcedIdが重複しています" if data_by_sourced_id.key?(new_data.sourced_id)
@data << new_data
@cache.clear
end
|
#check_semantically_consistent ⇒ Object
23
24
25
26
|
# File 'lib/meibo/data_set.rb', line 23
def check_semantically_consistent
raise SourcedIdDuplicatedError, "sourcedIdが重複しています" unless @data.size == data_by_sourced_id.size
raise DataNotFoundError, "sourcedIdがありません" unless data_by_sourced_id[nil].nil?
end
|
#each ⇒ Object
28
29
30
|
# File 'lib/meibo/data_set.rb', line 28
def each(...)
@data.each(...)
end
|
#empty? ⇒ Boolean
32
33
34
|
# File 'lib/meibo/data_set.rb', line 32
def empty?
@data.empty?
end
|
#find(sourced_id) ⇒ Object
36
37
38
39
40
|
# File 'lib/meibo/data_set.rb', line 36
def find(sourced_id)
data_by_sourced_id.fetch(sourced_id)
rescue KeyError
raise DataNotFoundError, "sourcedId: #{sourced_id} が見つかりません"
end
|
#lineno(datum) ⇒ Object
42
43
44
45
|
# File 'lib/meibo/data_set.rb', line 42
def lineno(datum)
find_index(datum)&.+(2)
end
|
#where(**conditions) ⇒ Object
47
48
49
|
# File 'lib/meibo/data_set.rb', line 47
def where(**conditions)
group_cache[conditions.keys.sort][conditions.values] || empty_set
end
|