class Enolib::SectionElement

Attributes

instruction[R]

Public Instance Methods

_untouched() click to toggle source
# File lib/enolib/elements/section_element.rb, line 7
def _untouched
  unless instance_variable_defined?(:@yielded)
    return instance_variable_defined?(:@touched) ? false : @instruction
  end

  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() click to toggle source
# File lib/enolib/elements/section_element.rb, line 19
def to_empty
  unless instance_variable_defined?(:@empty)
    unless @instruction[:type] == :empty
      # TODO: Below and in all implementations - why nil for key as second parameter?
      raise Errors::Validation.unexpected_element_type(@context, nil, @instruction, 'expected_empty')
    end

    @empty = Empty.new(@context, @instruction, @parent)
    @yielded = :empty
  end

  @empty
end
to_field() click to toggle source
# File lib/enolib/elements/section_element.rb, line 33
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] == :field_or_fieldset_or_list
      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() click to toggle source
# File lib/enolib/elements/section_element.rb, line 52
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] == :field_or_fieldset_or_list
      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() click to toggle source
# File lib/enolib/elements/section_element.rb, line 69
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] == :field_or_fieldset_or_list
      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() click to toggle source
# File lib/enolib/elements/section_element.rb, line 86
def to_s
  "#<Enolib::SectionElement key=#{_key} yields=#{_yields}>"
end
to_section() click to toggle source
# File lib/enolib/elements/section_element.rb, line 90
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() click to toggle source
# File lib/enolib/elements/section_element.rb, line 103
def touch
  # TODO: Revisit setting touched on foreign instances
  if !instance_variable_defined?(:@yielded)
    @touched = true
  elsif instance_variable_defined?(:@empty)
    @empty.touched = true
  elsif instance_variable_defined?(:@field)
    @field.touched = true
  elsif instance_variable_defined?(:@fieldset)
    @fieldset.touch
  elsif instance_variable_defined?(:@list)
    @list.touch
  elsif instance_variable_defined?(:@section)
    @section.touch
  end
end
yields_empty?() click to toggle source
# File lib/enolib/elements/section_element.rb, line 120
def yields_empty?
  @instruction[:type] == :empty
end
yields_field?() click to toggle source
# File lib/enolib/elements/section_element.rb, line 124
def yields_field?
  @instruction[:type] == :field ||
  @instruction[:type] == :multiline_field_begin ||
  @instruction[:type] == :field_or_fieldset_or_list
end
yields_fieldset?() click to toggle source
# File lib/enolib/elements/section_element.rb, line 130
def yields_fieldset?
  @instruction[:type] == :fieldset ||
  @instruction[:type] == :field_or_fieldset_or_list
end
yields_list?() click to toggle source
# File lib/enolib/elements/section_element.rb, line 135
def yields_list?
  @instruction[:type] == :list ||
  @instruction[:type] == :field_or_fieldset_or_list
end
yields_section?() click to toggle source
# File lib/enolib/elements/section_element.rb, line 140
def yields_section?
  @instruction[:type] == :section
end

Private Instance Methods

_yields() click to toggle source
# File lib/enolib/elements/section_element.rb, line 146
def _yields
  if @instruction[:type] == :field_or_fieldset_or_list
      return "#{PRETTY_TYPES[:field]},#{PRETTY_TYPES[:fieldset]},#{PRETTY_TYPES[:list]}"
  end

  PRETTY_TYPES[@instruction[:type]]
end