Sha256: 817c5a8b84f76c08134b0d1a5128fd3eb98dd6ee17652895e48a40e85706921f
Contents?: true
Size: 993 Bytes
Versions: 39
Compression:
Stored size: 993 Bytes
Contents
module Avo module Fields module Concerns module ItemLabels extend ActiveSupport::Concern def value_for_item(item) if @field.acts_as_taggable_on.present? item["value"] else item end end def label_from_item(item) return item[:label] if item.is_a?(Hash) && item[:label].present? value = value_for_item item if suggestions_are_a_hash? return suggestions_by_id[value.to_s][:label] if suggestions_by_id[value.to_s].present? end value end def suggestions_by_id return {} unless suggestions_are_a_hash? @field.suggestions.map do |suggestion| [suggestion[:value].to_s, suggestion] end.to_h end def suggestions_are_a_hash? return false if @field.suggestions.blank? @field.suggestions.first.is_a? Hash end end end end end
Version data entries
39 entries across 39 versions & 1 rubygems