Module: Dogviz::Common
Instance Method Summary collapse
- #ancestors ⇒ Object
- #create_id(name, parent) ⇒ Object
- #doclink(url) ⇒ Object
- #in_rollup? ⇒ Boolean
- #in_skip? ⇒ Boolean
- #info(fields) ⇒ Object
- #inherited_render_options ⇒ Object
- #label_with_info ⇒ Object
- #on_top_rollup? ⇒ Boolean
- #rollup! ⇒ Object
- #rollup? ⇒ Boolean
- #root ⇒ Object
- #setup_render_attributes(attributes) ⇒ Object
- #skip! ⇒ Object
- #skip? ⇒ Boolean
- #under_rollup? ⇒ Boolean
- #under_skip? ⇒ Boolean
Instance Method Details
#ancestors ⇒ Object
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 |
#doclink(url) ⇒ Object
29 30 31 |
# File 'lib/dogviz/common.rb', line 29 def doclink(url) setup_render_attributes(URL: url) end |
#in_rollup? ⇒ Boolean
76 77 78 |
# File 'lib/dogviz/common.rb', line 76 def in_rollup? rollup? || under_rollup? end |
#in_skip? ⇒ 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_options ⇒ Object
84 85 86 87 88 |
# File 'lib/dogviz/common.rb', line 84 def inherited = {} inherited[:fontname] = parent.[:fontname] if parent..include?(:fontname) inherited end |
#label_with_info ⇒ Object
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
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
46 47 48 |
# File 'lib/dogviz/common.rb', line 46 def rollup? @rollup end |
#root ⇒ Object
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
60 61 62 |
# File 'lib/dogviz/common.rb', line 60 def skip? @skip end |
#under_rollup? ⇒ Boolean
72 73 74 |
# File 'lib/dogviz/common.rb', line 72 def under_rollup? ancestors.any?(&:rollup?) end |
#under_skip? ⇒ Boolean
68 69 70 |
# File 'lib/dogviz/common.rb', line 68 def under_skip? ancestors.any?(&:skip?) end |