Eno::Fieldset ยป #entry

entry(name) โ†’ value or nil
entry(name, loader) โ†’ value or nil
entry(name, enforce_element: false, required: false, with_element: false) โ†’ object/value or nil

Retrieve an entry's value from the fieldset, optionally supplying a loader to validate and/or transform the value, and/or an options object.

enoQ&A:
Meaning = 42
Green = Yes
Purpose =
rubydocument = Eno.parse(input)
qa = document.fieldset('Q&A')

qa.entry('Meaning')   #=> '42'
qa.entry('Purpose')   #=> nil

qa.entry('Purpose', required: true)   # raises an error
qa.entry('Purpose', enforce_element: true)   #=> nil
qa.entry('Beige', enforce_element: true)   # raises an error

qa.entry('Green', Proc.new { |name, value| value.upcase })   #=> 'YES'

qa.entry('Meaning') do |name, value|  # raises an error
  raise "That one's getting old!" if value == '42'
  value
end

qa.entry('Meaning', with_element: true)   #=> [ #<Eno::Field name="Meaning" value="42"> , '42' ]

Parameters

name

The name of the entry as a string.

loader

A Proc returning the transformed/validated value or raising an error.The Proc is passed name and value as arguments.

options

enforce_element

Whether the entry must be present in the document (true or false, defaults to false)

enforce_value

Whether there must be a value or the entry is allowed to be empty (default to false)

required

Alias for enforce_value (this exists on many methods and depending on context refers to either element or value)

with_element

Whether to return an array with both the element and the value (defaults to false)

Return value

The entry's value, or nil if empty.