Eno::Fieldset » #element

element(name) → element or nil
element(name, options) → element or nil

Retrieve a single entry as Eno::Field (instead of its direct value) from the fieldset by its name. Optionally specify whether it's optional or mandatory for the entry to be present in the eno document (by default it's optional).

enoyears:
2007 = Year of the gooseberry
2010 = Year of the awesome beanstalk
2011 = Year of yearning
rubyfieldset = Eno.parse(input).fieldset('years')

fieldset.element('2010')  #=> #<Eno::Field name="2010" value="Year of the awesome beanstalk">
fieldset.element('2020')  #=> nil
fieldset.element('2020', enforce_element: true)  # raises an error
fieldset.element('2020', required: true)  # raises an error

Parameters

name

The name of the entry to fetch from the fieldset as a string.

options

enforce_element

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

required

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

Return value

An element (Eno::Field) or nil.