Class: Xumlidot::Parsers::KlassDefinition
- Inherits:
-
MethodBasedSexpProcessor
- Object
- MethodBasedSexpProcessor
- Xumlidot::Parsers::KlassDefinition
- Defined in:
- lib/xumlidot/parsers/klass_definition.rb
Overview
Parser for the KLASS DEFINITION ONLY
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Method Summary collapse
-
#initialize(exp, namespace = nil) ⇒ KlassDefinition
constructor
A new instance of KlassDefinition.
-
#process_class(exp) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
- #process_colon2(exp) ⇒ Object
- #process_colon3(exp) ⇒ Object
-
#process_const(exp) ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength.
Constructor Details
#initialize(exp, namespace = nil) ⇒ KlassDefinition
Returns a new instance of KlassDefinition.
12 13 14 15 16 17 18 19 |
# File 'lib/xumlidot/parsers/klass_definition.rb', line 12 def initialize(exp, namespace = nil) super() @definition = ::Xumlidot::Types::KlassDefinition.new @namespace = namespace.dup process(exp) end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
10 11 12 |
# File 'lib/xumlidot/parsers/klass_definition.rb', line 10 def definition @definition end |
Instance Method Details
#process_class(exp) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/xumlidot/parsers/klass_definition.rb', line 23 def process_class(exp) exp.shift # remove :class definition = exp.shift # Processes the name of the class if Sexp === definition # rubocop:disable Style/CaseEquality case definition.sexp_type when :colon2 # Reached in the event that a name is a compound name = definition.flatten name.delete :const name.delete :colon2 name.each do |v| @definition.name << ::Xumlidot::Types::Constant.new(v, @namespace) end when :colon3 # Reached in the event that a name begins with :: @definition.name << ::Xumlidot::Types::Constant.new(definition.last, '::') else raise "unknown type #{exp.inspect}" end # TODO: looks like a bug - fix when we get specs else # Symbol === definition # if we have a symbol we have the actual class name e.g. class Foo; end @definition.name << ::Xumlidot::Types::Constant.new(definition, @namespace) end # Processess inheritance process_until_empty(exp) s() end |
#process_colon2(exp) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/xumlidot/parsers/klass_definition.rb', line 63 def process_colon2(exp) exp.shift # remove :colon2 @definition.superklass << exp.value process_until_empty(exp) s() end |
#process_colon3(exp) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/xumlidot/parsers/klass_definition.rb', line 70 def process_colon3(exp) exp.shift # remove :colon3 @definition.superklass << '::' @definition.superklass << exp.value process_until_empty(exp) s() end |
#process_const(exp) ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength
56 57 58 59 60 61 |
# File 'lib/xumlidot/parsers/klass_definition.rb', line 56 def process_const(exp) # TODO: may have removed a shift by mistake @definition.superklass << exp.value process_until_empty(exp) s() end |