Class: TalltyImportExport::ExportPayload::CellColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/tallty_import_export/export_payload/cell_column.rb

Overview

一个 最大的竖列,分子列前的竖列

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, value, context, &value_handler) ⇒ CellColumn

Returns a new instance of CellColumn.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tallty_import_export/export_payload/cell_column.rb', line 5

def initialize header, value, context, &value_handler
  @header = header
  @value = value
  @context = context
  @cell_clusters = []
  @value_handler = value_handler

  val = @value_handler.call(@value.value, @header.as_json.symbolize_keys, keep_array: true)
  if header.children && val.is_a?(Array)
    @cell_clusters = val.map do |val|
      TalltyImportExport::ExportPayload::Cell.new(
        @header,
        TalltyImportExport::ExportPayload::Value.new(val, @value.chain),
        @context,
        &@value_handler
      )
    end
  else
    @cell_clusters = [
      TalltyImportExport::ExportPayload::Cell.new(
        @header,
        TalltyImportExport::ExportPayload::Value.new(
          @value_handler.call(@value.value, @header.as_json.symbolize_keys),
          @value.chain,
        ),
        @context,
        &@value_handler
      )
    ]
  end

  @flatten_cells = []

  cell_divise
end

Instance Attribute Details

#cell_clustersObject (readonly)

Returns the value of attribute cell_clusters.



3
4
5
# File 'lib/tallty_import_export/export_payload/cell_column.rb', line 3

def cell_clusters
  @cell_clusters
end

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/tallty_import_export/export_payload/cell_column.rb', line 3

def context
  @context
end

#flatten_cellsObject (readonly)

Returns the value of attribute flatten_cells.



3
4
5
# File 'lib/tallty_import_export/export_payload/cell_column.rb', line 3

def flatten_cells
  @flatten_cells
end

#headerObject (readonly)

Returns the value of attribute header.



3
4
5
# File 'lib/tallty_import_export/export_payload/cell_column.rb', line 3

def header
  @header
end

#payloadObject (readonly)

Returns the value of attribute payload.



3
4
5
# File 'lib/tallty_import_export/export_payload/cell_column.rb', line 3

def payload
  @payload
end

#tallest_cell_clusterObject (readonly)

Returns the value of attribute tallest_cell_cluster.



3
4
5
# File 'lib/tallty_import_export/export_payload/cell_column.rb', line 3

def tallest_cell_cluster
  @tallest_cell_cluster
end

Instance Method Details

#cell_diviseObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tallty_import_export/export_payload/cell_column.rb', line 41

def cell_divise
  divised_cell_clusters = @cell_clusters.map do |cell_cluster|
    cell_cluster.divise.cell_cluster
  end

  @flatten_cells = divised_cell_clusters.flatten

  depth_to_cells_mapping = @flatten_cells.group_by { |cell| [cell.header.seq] }

  @tallest_cell_cluster = depth_to_cells_mapping.values.max { |a, b| a.count <=> b.count } || []

  self
end