Module: Unicoder::MultiDimensionalArrayBuilder

Included in:
Builder::Categories, Builder::DisplayWidth, Builder::Scripts, Builder::Types
Defined in:
lib/unicoder/multi_dimensional_array_builder.rb

Overview

Include after Builder

Instance Method Summary collapse

Instance Method Details

#assign_codepoint(codepoint, value, index = @index) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/unicoder/multi_dimensional_array_builder.rb', line 10

def assign_codepoint(codepoint, value, index = @index)
  plane         = codepoint    / 0x10000
  plane_offset  = codepoint    % 0x10000
  row           = plane_offset / 0x1000
  row_offset    = plane_offset % 0x1000
  byte          = row_offset   / 0x100
  byte_offset   = row_offset   % 0x100
  nibble        = byte_offset  / 0x10
  nibble_offset = byte_offset  % 0x10

  index[plane] ||= []
  index[plane][row] ||= []
  index[plane][row][byte] ||= []
  index[plane][row][byte][nibble] ||= []
  index[plane][row][byte][nibble][nibble_offset] = value
end

#compress!(index = @index) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/unicoder/multi_dimensional_array_builder.rb', line 27

def compress!(index = @index)
  index.map!{ |plane|
    if !plane.is_a?(Array)
      plane
    elsif plane.flatten.uniq.size == 1
      plane[0]
    else
      plane.map!{ |row|
        if !row.is_a?(Array)
          row
        elsif row.flatten.uniq.size == 1
          row[0]
        else
          row.map!{ |byte|
            if !byte.is_a?(Array)
              byte
            elsif byte.uniq.size == 1
              byte[0]
            else
              byte.map! { |nibble|
                if !nibble.is_a?(Array)
                  nibble
                elsif nibble.uniq.size == 1
                  nibble[0]
                else
                  nibble
                end
              }
            end
          }
        end
      }
    end
  }
end

#initialize_indexObject



6
7
8
# File 'lib/unicoder/multi_dimensional_array_builder.rb', line 6

def initialize_index
  @index = []
end

#remove_trailing_nils!(index = @index) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/unicoder/multi_dimensional_array_builder.rb', line 63

def remove_trailing_nils!(index = @index)
  index.each{ |plane|
    if plane.is_a?(Array)
      plane.pop while plane[-1] == nil
      plane.each{ |row|
        if row.is_a?(Array)
        row.pop while row[-1] == nil
        row.each{ |byte|
          if byte.is_a?(Array)
            byte.pop while byte[-1] == nil
            byte.each{ |nibble|
              if nibble.is_a?(Array)
                nibble.pop while nibble[-1] == nil
              end
            }
          end
        }
        end
    }
    end
  }
end