Module: Dogviz::Common

Included in:
Container, Thing
Defined in:
lib/dogviz/common.rb

Instance Method Summary collapse

Instance Method Details

#ancestorsObject



14
15
16
17
18
19
20
21
# File 'lib/dogviz/common.rb', line 14

def ancestors
  ancestors = [parent]
  loop do
    break unless ancestors.last.respond_to?(:parent)
    ancestors << ancestors.last.parent
  end
  ancestors
end

#create_id(name, parent) ⇒ Object



3
4
5
6
7
8
# File 'lib/dogviz/common.rb', line 3

def create_id(name, parent)
  parts = []
  parts << parent.id if parent.respond_to? :id
  parts += name.split(/\s/)
  parts.join '_'
end


29
30
31
# File 'lib/dogviz/common.rb', line 29

def doclink(url)
  setup_render_attributes(URL: url)
end

#in_rollup?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/dogviz/common.rb', line 76

def in_rollup?
  rollup? || under_rollup?
end

#in_skip?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/dogviz/common.rb', line 64

def in_skip?
  skip? || under_skip?
end

#info(fields) ⇒ Object



23
24
25
26
27
# File 'lib/dogviz/common.rb', line 23

def info(fields)
  @info.merge! fields
  setup_render_attributes(label: label_with_info)
  self
end

#inherited_render_optionsObject



84
85
86
87
88
# File 'lib/dogviz/common.rb', line 84

def inherited_render_options
  inherited = {}
  inherited[:fontname] = parent.render_options[:fontname] if parent.render_options.include?(:fontname)
  inherited
end

#label_with_infoObject



33
34
35
36
37
38
39
# File 'lib/dogviz/common.rb', line 33

def label_with_info
  lines = [name]
  @info.each { |k, v|
    lines << "#{k}: #{v}"
  }
  lines.join "\n"
end

#on_top_rollup?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/dogviz/common.rb', line 80

def on_top_rollup?
  rollup? && !under_rollup?
end

#rollup!Object



50
51
52
53
# File 'lib/dogviz/common.rb', line 50

def rollup!
  @rollup = true
  self
end

#rollup?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/dogviz/common.rb', line 46

def rollup?
  @rollup
end

#rootObject



10
11
12
# File 'lib/dogviz/common.rb', line 10

def root
  ancestors.last
end

#setup_render_attributes(attributes) ⇒ Object



41
42
43
44
# File 'lib/dogviz/common.rb', line 41

def setup_render_attributes(attributes)
  @attributes ||= {}
  @attributes.merge!(attributes)
end

#skip!Object



55
56
57
58
# File 'lib/dogviz/common.rb', line 55

def skip!
  @skip = true
  self
end

#skip?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/dogviz/common.rb', line 60

def skip?
  @skip
end

#under_rollup?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/dogviz/common.rb', line 72

def under_rollup?
  ancestors.any?(&:rollup?)
end

#under_skip?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/dogviz/common.rb', line 68

def under_skip?
  ancestors.any?(&:skip?)
end