Sha256: cc95486002ce758ce676dc21426d6a294157530f7f5852f421cd1e8429c2a412
Contents?: true
Size: 1.7 KB
Versions: 2
Compression:
Stored size: 1.7 KB
Contents
module RTM::Sugar module Topic module HashAccess def [](cref) raise "Characteristic reference must be a String" unless cref.is_a? String is_name, type_reference, scope_reference = resolve_characteristic(cref) if is_name type_reference = RTM::PSI[:name_type] if type_reference == :any names.select{|n| n.type == topic_map.get(type_reference)} else raise "No occurrence type given" if type_reference == :any occurrences.select{|o| o.type == topic_map.get(type_reference)} end end def []=(cref, value) is_name, type_reference, scope_reference = resolve_characteristic(cref) if is_name type_reference = nil if type_reference == :any nametype = type_reference || topic_map.get!(RTM::PSI[:name_type]) n = create_name(value, nametype) n else raise "No occurrence type given" if type_reference == :any o = create_occurrence(value, type_reference) o end end private def resolve_characteristic(ref) ref =~ /^(-\s*)?(.+)?$/ is_name = $1 ? true : false type, scope = resolve_type_and_scope($2) [is_name, type, scope] end def resolve_type_and_scope(ref) return [:any, :any] unless ref return [ref, :ucs] if ref.is_a? Topic type, scope = ref.split('@', -1) if type.blank? type = :any else type.strip! end if scope scope = scope.strip.split(/\s+/) scope = :ucs if scope.blank? else scope = :any end [type, scope] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rtm-0.1.5 | lib/rtm/sugar/topic/hash_access.rb |
rtm-0.1.6 | lib/rtm/sugar/topic/hash_access.rb |