Class: Meibo::DataSet

Inherits:
Object
  • 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

#rosterObject (readonly)

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

Raises:



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/meibo/data_set.rb', line 15

def <<(new_data)
  raise DataNotFoundError, "sourcedIdがありません" unless new_data.sourced_id

  if data_by_sourced_id.key?(new_data.sourced_id)
    raise SourcedIdDuplicatedError,
          "sourcedId\u304C\u91CD\u8907\u3057\u3066\u3044\u307E\u3059"
  end

  @data << new_data
  @cache.clear
end

#check_semantically_consistentObject

Raises:



27
28
29
30
31
32
33
34
# File 'lib/meibo/data_set.rb', line 27

def check_semantically_consistent
  unless @data.size == data_by_sourced_id.size
    raise SourcedIdDuplicatedError,
          "sourcedId\u304C\u91CD\u8907\u3057\u3066\u3044\u307E\u3059"
  end

  raise DataNotFoundError, "sourcedIdがありません" unless data_by_sourced_id[nil].nil?
end

#eachObject



36
37
38
# File 'lib/meibo/data_set.rb', line 36

def each(...)
  @data.each(...)
end

#empty?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/meibo/data_set.rb', line 40

def empty?
  @data.empty?
end

#find(sourced_id) ⇒ Object



44
45
46
47
48
# File 'lib/meibo/data_set.rb', line 44

def find(sourced_id)
  data_by_sourced_id.fetch(sourced_id)
rescue KeyError
  raise DataNotFoundError, "sourcedId: #{sourced_id} が見つかりません"
end

#lineno(datum) ⇒ Object



50
51
52
53
# File 'lib/meibo/data_set.rb', line 50

def lineno(datum)
  # NOTE: add one for one-based, and add one for header line
  find_index(datum)&.+(2)
end

#where(**conditions) ⇒ Object



55
56
57
# File 'lib/meibo/data_set.rb', line 55

def where(**conditions)
  group_cache[conditions.keys.sort][conditions.values] || empty_set
end