Sha256: 3dcf93c43ef95689592e53d9713b941277ba1f693aa406ff89e61496a62c27e0
Contents?: true
Size: 1.97 KB
Versions: 6
Compression:
Stored size: 1.97 KB
Contents
# -*- encoding : utf-8 -*- # require "card/env" require "cardname" class Card # The Cardname class provides generalized of Card naming patterns # (compound names, key-based variants, etc) # # Card::Name adds support for deeper card integration class Name < Cardname include FieldsAndTraits include NameVariants class << self def [] *cardish cardish = cardish.first if cardish.size <= 1 case cardish when Card then cardish.name when Symbol, Integer then Card.fetch_name(cardish) when Array then smart_compose cardish when String, NilClass then new cardish else raise ArgumentError, "#{cardish.class} not supported as name identifier" end end def session Card::Auth.current.name # also_yuck end def params Card::Env.params end def new str, validated_parts=nil return compose str if str.is_a?(Array) str = str.to_s if !validated_parts && str.include?(joint) compose Cardname.split_parts(str) elsif (id = Card.id_from_string(str)) # handles ~ and : Card.fetch_name(id) { Card.bad_mark(str) } else super str end end # interprets symbols/integers as codenames/ids def smart_compose parts name_parts = parts.flatten.map { |part| self[part] } new name_parts.join(joint), true end def compose parts name_parts = parts.flatten.map { |part| new part } new name_parts.join(joint), true end def url_key_to_standard key key.to_s.tr "_", " " end end def star? simple? && s[0, 1] == "*" end def rstar? right && right[0, 1] == "*" end def code Card::Codename[Card.fetch_id self] end def setting? Set::Type::Setting.member_names[key] end def set? Set::Pattern.card_keys[tag_name.key] end end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
card-1.101.4 | lib/card/name.rb |
card-1.101.3 | lib/card/name.rb |
card-1.101.2 | lib/card/name.rb |
card-1.101.1 | lib/card/name.rb |
card-1.101.0 | lib/card/name.rb |
card-1.100.0 | lib/card/name.rb |