# ITEM LISTS # Note: while most methods for returning lists of items can handle arguments, # they are most commonly used without them. # @return [Array] list of Card::Name objects # @param args [Hash] # @option args [String] :content override card content # @option args [String, Card::Name, Symbol] :context name in whose context relative items # will be interpreted. For example. +A in context of B is interpreted as B+A # context defaults to pointer card's name. If value is `:raw`, then name is not # contextualized # @option args [String, Integer] :limit max number of cards to return # @option args [String, Integer] :offset begin after the offset-th item def item_names args={} seeding_names do context = args[:context] item_strings(args).map do |item| clean_item_name item, context end.compact end end # @return [Array] list of cards # @param args [Hash] see #item_names def item_cards args={} standard_item_cards args end # @return [Array] list of integers (card ids of items) # @param args [Hash] see #item_names def item_ids args={} item_names(args).map(&:card_id).compact end # @return [Array] of String objects # @param args [Hash] see #item_names def item_keys args={} item_names(args).map do |item| item.to_name.key end end # @return [Array] of String objects # @param args [Hash] see #item_names def item_strings args={} items = raw_item_strings(args[:content] || content) return items unless args.present? filtered_items items, limit: args[:limit], offset: args[:offset] end # SINGLE ITEM # @return [Card::Name] # @param args [Hash] see #item_names def first_name args={} item_names(args).first end # @return [Card] # @param args [Hash] see #item_names def first_card args={} return unless (name = first_name) fetch_item_card name, args end # @return [Symbol] # @param args [Hash] see #item_names def first_code args={} first_card(args)&.codename end # @return [Integer] # @param args [Hash] see #item_names def first_id args={} first_name(args)&.card_id end # ITEM TYPES # typically override EITHER #item_type_id OR #item_type_name def item_type_id @item_type_id ||= no_item_type_recursion { item_type_name&.card_id } end def item_type_name @item_type_name ||= no_item_type_recursion { item_type_id&.cardname } end def item_type_card item_type_id&.card end # MISC def item_count args={} item_names(args).size end def include_item? item item_names.include? Card::Name[item] end # for override, eg by json def item_value item_name item_name end format do view :count do try :count end def nest_item cardish, options={}, &block options = item_view_options options options[:nest_name] = Card::Name[cardish].s nest cardish, options, &block end def item_links args={} card.item_cards(args).map do |item_card| nest_item item_card, view: :link end end def implicit_item_view view = voo_items_view || default_item_view Card::View.normalize view end def voo_items_view return unless voo && (items = voo.items) items[:view] end def default_item_view :name end def item_view_options new_options={} options = (voo.items || {}).clone options = options.merge new_options options[:view] ||= implicit_item_view determine_item_view_options_type options options end def determine_item_view_options_type options return if options[:type] type_name = card.item_type_name options[:type] = type_name if type_name end def listing listing_cards, item_args={} listing_cards.map do |item_card| nest_item item_card, item_args do |rendered, item_view| wrap_item rendered, item_view end end end def wrap_item item, _args={} item # no wrap in base end end format :html do view :count do number_with_delimiter try(:count) end def wrap_item rendered, item_view %(