class Enolib::List

Attributes

instruction[R]

Public Instance Methods

_instantiate_items(list) click to toggle source
# File lib/enolib/elements/list.rb, line 7
def _instantiate_items(list)
  if list.has_key?(:mirror)
    _instantiate_items(list[:mirror])
  elsif list.has_key?(:extend)
    _instantiate_items(list[:extend]) + list[:items].map { |item| ListItem.new(@context, item, self) }
  elsif list.has_key?(:items)
    list[:items].map { |item| ListItem.new(@context, item, self) }
  else
    []
  end
end
_items() click to toggle source
# File lib/enolib/elements/list.rb, line 19
def _items
  unless instance_variable_defined?(:@instantiated_items)
    @instantiated_items = _instantiate_items(@instruction)
  end

  @instantiated_items
end
_untouched() click to toggle source
# File lib/enolib/elements/list.rb, line 27
def _untouched
  return @instruction unless instance_variable_defined?(:@touched)

  untouched_item = _items.find { |item| !item.instance_variable_defined?(:@touched) }

  untouched_item ? untouched_item.instruction : false
end
items() click to toggle source
# File lib/enolib/elements/list.rb, line 35
def items
  @touched = true

  _items
end
length() click to toggle source
# File lib/enolib/elements/list.rb, line 41
def length
  @touched = true

  _items.length
end
optional_comment(loader = nil) click to toggle source
# File lib/enolib/elements/list.rb, line 47
def optional_comment(loader = nil)
  loader = Proc.new if block_given?

  if loader
    _comment(loader, required: false)
  else
    raise ArgumentError, 'A loader block or Proc must be provided'
  end
end
optional_string_values() click to toggle source
# File lib/enolib/elements/list.rb, line 57
def optional_string_values
  @touched = true

  _items.map(&:optional_string_value)
end
optional_values(loader = nil) click to toggle source
# File lib/enolib/elements/list.rb, line 63
def optional_values(loader = nil)
  loader = Proc.new if block_given?

  @touched = true

  unless loader
    raise ArgumentError, 'A loader function must be provided'
  end

  _items.map { |item| item.optional_value(loader) }
end
parent() click to toggle source
# File lib/enolib/elements/list.rb, line 75
def parent
  @parent || Section.new(@context, @instruction[:parent])
end
required_string_values() click to toggle source
# File lib/enolib/elements/list.rb, line 79
def required_string_values
  @touched = true

  _items.map(&:required_string_value)
end
required_values(loader = nil) click to toggle source
# File lib/enolib/elements/list.rb, line 85
def required_values(loader = nil)
  loader = Proc.new if block_given?

  @touched = true

  unless loader
    raise ArgumentError, 'A loader function must be provided'
  end

  _items.map { |item| item.required_value(loader) }
end
to_s() click to toggle source
# File lib/enolib/elements/list.rb, line 97
def to_s
  "#<Enolib::List key=#{@instruction[:key]} items=#{_items.length}>"
end
touch() click to toggle source
# File lib/enolib/elements/list.rb, line 101
def touch
  @touched = true

  _items.each(&:touch)
end