Class: RDL::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/rdl/info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInfo

Returns a new instance of Info.



9
10
11
# File 'lib/rdl/info.rb', line 9

def initialize
  @info = Hash.new
end

Instance Attribute Details

#infoObject

map from klass (String) to label (Symbol) to kind (Symbol) to either array or some other value

class names are strings because they need to be manipulated in case they include

(class names may have Util.add_singleton_marker applied to them to indicate they’re singleton classes.)



7
8
9
# File 'lib/rdl/info.rb', line 7

def info
  @info
end

Instance Method Details

#add(klass, label, kind, val) ⇒ Object

kind

must map to an array



14
15
16
17
18
19
20
21
# File 'lib/rdl/info.rb', line 14

def add(klass, label, kind, val)
  klass = klass.to_s
  label = label.to_sym
  @info[klass] = {} unless @info[klass]
  @info[klass][label] = {} unless @info[klass][label]
  @info[klass][label][kind] = [] unless @info[klass][label][kind]
  @info[klass][label][kind] << val
end

#get(klass, label, kind) ⇒ Object

eventually replace with Hash#dig



64
65
66
67
68
69
70
71
72
73
# File 'lib/rdl/info.rb', line 64

def get(klass, label, kind)
  klass = klass.to_s
  label = label.to_sym
  t1 = @info[klass]
  return t1 if t1.nil?
  t2 = t1[label]
  return t2 if t2.nil?
  return t2[kind]
#    return @info[klass][label][kind]
end

#get_with_aliases(klass, label, kind) ⇒ Object



75
76
77
78
79
80
# File 'lib/rdl/info.rb', line 75

def get_with_aliases(klass, label, kind)
  while RDL::Globals.aliases[klass] && RDL::Globals.aliases[klass][label]
    label = RDL::Globals.aliases[klass][label]
  end
  get(klass, label, kind)
end

#has?(klass, label, kind) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/rdl/info.rb', line 47

def has?(klass, label, kind)
  klass = klass.to_s
  label = label.to_sym
  return (@info.has_key? klass) &&
         (@info[klass].has_key? label) &&
         (@info[klass][label].has_key? kind)
end

#has_any?(klass, label, kinds) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
# File 'lib/rdl/info.rb', line 55

def has_any?(klass, label, kinds)
  klass = klass.to_s
  label = label.to_sym
  return (@info.has_key? klass) &&
         (@info[klass].has_key? label) &&
         (kinds.any? { |k| @info[klass][label].has_key? k })
end

#remove(klass, label, kind) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/rdl/info.rb', line 82

def remove(klass, label, kind)
  klass = klass.to_s
  label = label.to_sym
  return unless @info.has_key? klass
  return unless @info[klass].has_key? label
  @info[klass][label].delete kind
end

#set(klass, label, kind, val) ⇒ Object

if no prev info for kind, set to val and return true if prev info for kind, return true if prev == val and false otherwise



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rdl/info.rb', line 25

def set(klass, label, kind, val)
  klass = RDL::Util.to_class_str(klass)
  label = label.to_sym
  @info[klass] = {} unless @info[klass]
  @info[klass][label] = {} unless @info[klass][label]
  if @info[klass][label].has_key? kind
    return (val == @info[klass][label][kind])
  else
    @info[klass][label][kind] = val
    return true
  end
end

#set!(klass, label, kind, val) ⇒ Object

replace info for kind



39
40
41
42
43
44
45
# File 'lib/rdl/info.rb', line 39

def set!(klass, label, kind, val)
  klass = klass.to_s
  label = label.to_sym
  @info[klass] = {} unless @info[klass]
  @info[klass][label] = {} unless @info[klass][label]
  @info[klass][label][kind] = val
end