Class: Slicer

Inherits:
Object
  • Object
show all
Defined in:
lib/slicer/slicer.rb,
lib/slicer/version.rb

Constant Summary collapse

VERSION =
"0.0.2"
@@colors =
["#00B85C",
"#00CC66",
"#19D175",
"#33D685",
"#4DDB94",
"#66E0A3",
"#80E6B2",
"#99EBC2",
"#B2F0D1",
"#CCF5E0",
"#E6FAF0",
"#0066CC",
"#1975D1",
"#3385D6",
"#4D94DB",
"#66A3E0",
"#80B2E6",
"#99C2EB",
"#B2D1F0",
"#CCE0F5",
"#E6F0FA"]
@@color_index =
0

Class Method Summary collapse

Class Method Details

.pop_colorObject



34
35
36
37
# File 'lib/slicer/slicer.rb', line 34

def self.pop_color
  @@color_index = (@@color_index == @@colors.length-1) ? @@color_index = 0 : @@color_index + 1
  @@colors[@@color_index]
end

.slice(root_slice, things, procs, current_depth = 0) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/slicer/slicer.rb', line 39

def self.slice(root_slice, things, procs, current_depth=0)
  root_slice ||= Slice.new("Root")
  root_slice.children ||= []

  unless procs.length == current_depth
    map = procs[current_depth].call(things)
    Array.wrap(map.keys).each do |kee|
      current_slice = Slice.new(kee)
      if(procs.length == current_depth+1)
        current_slice.color = pop_color
        current_slice.value = map[kee].length
      end
      root_slice.children << slice(current_slice, map[kee], procs, current_depth+1)
    end
  end
  root_slice.children = nil if root_slice.children.empty?
  root_slice
end