Class: Prettyrb::Document::Builder
- Inherits:
-
Object
- Object
- Prettyrb::Document::Builder
show all
- Includes:
- Enumerable
- Defined in:
- lib/prettyrb/document.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Builder
Returns a new instance of Builder.
42
43
44
|
# File 'lib/prettyrb/document.rb', line 42
def initialize(*args)
@parts = args
end
|
Instance Attribute Details
#parts ⇒ Object
Returns the value of attribute parts.
38
39
40
|
# File 'lib/prettyrb/document.rb', line 38
def parts
@parts
end
|
Instance Method Details
#each ⇒ Object
46
47
48
|
# File 'lib/prettyrb/document.rb', line 46
def each
@parts.each
end
|
#groups ⇒ Object
58
59
60
61
62
|
# File 'lib/prettyrb/document.rb', line 58
def groups
parts.select { |p| p.is_a?(Group) } + parts.flat_map do |p|
p.groups if p.respond_to?(:groups)
end.compact
end
|
#has_group_part? ⇒ Boolean
54
55
56
|
# File 'lib/prettyrb/document.rb', line 54
def has_group_part?
parts.any? { |p| p.is_a?(Group) }
end
|
#inspect ⇒ Object
50
51
52
|
# File 'lib/prettyrb/document.rb', line 50
def inspect
inspect_children(self, indent_level: 0)
end
|
#max_group_depth ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/prettyrb/document.rb', line 64
def max_group_depth
return 0 if !parts
return @max_group_depth if defined?(@max_group_depth)
has_groups = parts.any? { |p| p.is_a?(Group) }
total = if has_groups
1
else
0
end
nested_total = parts.
filter { |p| p.respond_to?(:max_group_depth) }.
flat_map { |p| p.max_group_depth }.
max
@max_group_depth = total + (nested_total || 0)
end
|