Sha256: 03df18d8c40e7fb5bef23a563aa5d0ad02e940886769d0302d28b6a45fdce284
Contents?: true
Size: 1.11 KB
Versions: 65
Compression:
Stored size: 1.11 KB
Contents
module Spree module Variants class OptionsPresenter WORDS_CONNECTOR = ', '.freeze attr_reader :variant delegate :option_values, to: :variant def initialize(variant) @variant = variant end def to_sentence options = option_values options = sort_options(options) options = present_options(options) join_options(options) end private def sort_options(options) options.sort_by { |o| o.option_type.position } end def present_options(options) options.map do |ov| method = "present_#{ov.option_type.name}_option" respond_to?(method, true) ? send(method, ov) : present_option(ov) end end def present_color_option(option) "#{option.option_type.presentation}: #{option.name}" end def present_option(option) "#{option.option_type.presentation}: #{option.presentation}" end def join_options(options) options.to_sentence(words_connector: WORDS_CONNECTOR, two_words_connector: WORDS_CONNECTOR) end end end end
Version data entries
65 entries across 65 versions & 1 rubygems