Class: Enolib::SectionElement
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from ElementBase
#comment_error, #error, #initialize, #key, #key_error, #optional_comment, #optional_string_comment, #raw, #required_comment, #required_string_comment, #string_key
Instance Attribute Details
#instruction ⇒ Object
TODO: Revisit this hacky exposition
5
6
7
|
# File 'lib/enolib/elements/section_element.rb', line 5
def instruction
@instruction
end
|
Instance Method Details
#_untouched ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/enolib/elements/section_element.rb', line 7
def _untouched
return @instruction unless instance_variable_defined?(:@yielded)
return @instruction if instance_variable_defined?(:@empty) && !@empty.instance_variable_defined?(:@touched)
return @instruction if instance_variable_defined?(:@field) && !@field.instance_variable_defined?(:@touched)
return @fieldset._untouched if instance_variable_defined?(:@fieldset)
return @list._untouched if instance_variable_defined?(:@list)
return @section._untouched if instance_variable_defined?(:@section)
end
|
#to_empty ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/enolib/elements/section_element.rb', line 17
def to_empty
unless instance_variable_defined?(:@empty)
if instance_variable_defined?(:@yielded)
raise TypeError, "This element was already yielded as #{PRETTY_TYPES[@yielded]} and can't be yielded again as an empty."
end
unless @instruction[:type] == :empty_element
raise Errors::Validation.unexpected_element_type(@context, nil, @instruction, 'expected_empty')
end
@empty = Empty.new(@context, @instruction, @parent)
@yielded = :empty_element
end
@empty
end
|
#to_field ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/enolib/elements/section_element.rb', line 35
def to_field
unless instance_variable_defined?(:@field)
if instance_variable_defined?(:@yielded)
raise TypeError, "This element was already yielded as #{PRETTY_TYPES[@yielded]} and can't be yielded again as a field."
end
unless @instruction[:type] == :field ||
@instruction[:type] == :multiline_field_begin ||
@instruction[:type] == :empty_element
raise Errors::Validation.unexpected_element_type(@context, nil, @instruction, 'expected_field')
end
@field = Field.new(@context, @instruction, @parent)
@yielded = :field
end
@field
end
|
#to_fieldset ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/enolib/elements/section_element.rb', line 54
def to_fieldset
unless instance_variable_defined?(:@fieldset)
if instance_variable_defined?(:@yielded)
raise TypeError, "This element was already yielded as #{PRETTY_TYPES[@yielded]} and can't be yielded again as a fieldset."
end
unless @instruction[:type] == :fieldset || @instruction[:type] == :empty_element
raise Errors::Validation.unexpected_element_type(@context, nil, @instruction, 'expected_fieldset')
end
@fieldset = Fieldset.new(@context, @instruction, @parent)
@yielded = :fieldset
end
@fieldset
end
|
#to_list ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/enolib/elements/section_element.rb', line 71
def to_list
unless instance_variable_defined?(:@list)
if instance_variable_defined?(:@yielded)
raise TypeError, "This element was already yielded as #{PRETTY_TYPES[@yielded]} and can't be yielded again as a list."
end
unless @instruction[:type] == :list || @instruction[:type] == :empty_element
raise Errors::Validation.unexpected_element_type(@context, nil, @instruction, 'expected_list')
end
@list = List.new(@context, @instruction, @parent)
@yielded = :list
end
@list
end
|
#to_s ⇒ Object
88
89
90
|
# File 'lib/enolib/elements/section_element.rb', line 88
def to_s
"#<Enolib::SectionElement key=#{_key} yields=#{_yields}>"
end
|
#to_section ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/enolib/elements/section_element.rb', line 92
def to_section
unless instance_variable_defined?(:@section)
unless @instruction[:type] == :section
raise Errors::Validation.unexpected_element_type(@context, nil, @instruction, 'expected_section')
end
@section = Section.new(@context, @instruction, @parent)
@yielded = :section
end
@section
end
|
#touch ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/enolib/elements/section_element.rb', line 105
def touch
return unless instance_variable_defined?(:@yielded)
@empty.touched = true if instance_variable_defined?(:@empty)
@field.touched = true if instance_variable_defined?(:@field)
@fieldset.touch if instance_variable_defined?(:@fieldset)
@list.touch if instance_variable_defined?(:@list)
@section.touch if instance_variable_defined?(:@section)
end
|
#yields_empty? ⇒ Boolean
117
118
119
|
# File 'lib/enolib/elements/section_element.rb', line 117
def yields_empty?
@instruction[:type] == :empty_element
end
|
#yields_field? ⇒ Boolean
121
122
123
124
125
|
# File 'lib/enolib/elements/section_element.rb', line 121
def yields_field?
@instruction[:type] == :field ||
@instruction[:type] == :multiline_field_begin ||
@instruction[:type] == :empty_element
end
|
#yields_fieldset? ⇒ Boolean
127
128
129
130
|
# File 'lib/enolib/elements/section_element.rb', line 127
def yields_fieldset?
@instruction[:type] == :fieldset ||
@instruction[:type] == :empty_element
end
|
#yields_list? ⇒ Boolean
132
133
134
135
|
# File 'lib/enolib/elements/section_element.rb', line 132
def yields_list?
@instruction[:type] == :list ||
@instruction[:type] == :empty_element
end
|
#yields_section? ⇒ Boolean
137
138
139
|
# File 'lib/enolib/elements/section_element.rb', line 137
def yields_section?
@instruction[:type] == :section
end
|