Class: IDL::AST::Annotation
- Inherits:
-
Object
- Object
- IDL::AST::Annotation
- Defined in:
- lib/ridl/node.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #[](fieldid) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(id, fields = {}) ⇒ Annotation
constructor
A new instance of Annotation.
- #is_marker? ⇒ Boolean
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
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
36 37 38 |
# File 'lib/ridl/node.rb', line 36 def fields @fields end |
#id ⇒ Object (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
38 39 40 |
# File 'lib/ridl/node.rb', line 38 def is_marker? @fields.empty? end |