Module: Wallaby::FieldUtils

Defined in:
lib/utils/wallaby/field_utils.rb

Overview

Field utils

Class Method Summary collapse

Class Method Details

.first_field_by(*conditions, fields) ⇒ String, Symbol

Find the first field that meets the first condition.

Examples:

to find the possible text field

Wallaby::FieldUtils.first_field_by({ name: /name|title/ }, { type: 'string' }, fields)
# => if any field name that includes `name` or `title`, return this field
# => otherwise, find the first field whose type is `string`

Parameters:

  • conditions (Array<Hash>)
  • fields (Hash)

    field metadata

Returns:

  • (String, Symbol)

    field name



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/utils/wallaby/field_utils.rb', line 15

def first_field_by(*conditions, fields)
  return if [conditions, fields].any?(&:blank?)

  conditions.each do |condition|
    fields.each do |field_name, |
      return field_name if meet? condition, field_name, 
    end
  end

  nil
end