Module: CustomFields::Types::Select::Field

Extended by:
ActiveSupport::Concern
Defined in:
lib/custom_fields/types/select.rb

Instance Method Summary collapse

Instance Method Details

#ordered_select_optionsObject



38
39
40
# File 'lib/custom_fields/types/select.rb', line 38

def ordered_select_options
  self.select_options.sort { |a, b| (a.position || 0) <=> (b.position || 0) }.to_a
end

#select_as_json(options = {}) ⇒ Object



50
51
52
# File 'lib/custom_fields/types/select.rb', line 50

def select_as_json(options = {})
  { 'select_options' => self.ordered_select_options.map(&:as_json) }
end

#select_to_recipeObject



42
43
44
45
46
47
48
# File 'lib/custom_fields/types/select.rb', line 42

def select_to_recipe
  {
    'select_options' => self.ordered_select_options.map do |option|
      { '_id' => option._id, 'name' => option.name_translations }
    end
  }
end