Class: IDL::AST::Annotation

Inherits:
Object
  • Object
show all
Defined in:
lib/ridl/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, fields = {}) ⇒ Annotation

Returns a new instance of Annotation.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ridl/node.rb', line 19

def initialize(id, fields = {})
  @id = id.to_sym
  # copy field map transforming all keys to symbols and
  # detecting nested annotation objects
  @fields = fields.inject({}) do |m,(k,v)|
      m[k.to_sym] = case v
          when Array
            v.collect { |ve| Hash === ve ? Annotation.new(*ve.to_a.first) : ve }
          when Hash
            Annotation.new(*v.to_a.first)
          else
            v
        end
      m
    end
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



36
37
38
# File 'lib/ridl/node.rb', line 36

def fields
  @fields
end

#idObject (readonly)

Returns the value of attribute id.



36
37
38
# File 'lib/ridl/node.rb', line 36

def id
  @id
end

Instance Method Details

#[](fieldid) ⇒ Object



42
43
44
# File 'lib/ridl/node.rb', line 42

def [](fieldid)
  @fields[(fieldid || '').to_sym]
end

#each(&block) ⇒ Object



46
47
48
# File 'lib/ridl/node.rb', line 46

def each(&block)
  @fields.each(&block)
end

#is_marker?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ridl/node.rb', line 38

def is_marker?
  @fields.empty?
end