Class: Lutaml::XMI::GeneralizationDrop

Inherits:
Liquid::Drop
  • Object
show all
Defined in:
lib/lutaml/xmi/liquid_drops/generalization_drop.rb

Instance Method Summary collapse

Constructor Details

#initialize(gen) ⇒ GeneralizationDrop

rubocop:disable Lint/MissingSuper



6
7
8
9
10
11
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 6

def initialize(gen) # rubocop:disable Lint/MissingSuper
  @gen = gen
  @looped_general_item = false
  @inherited_props = []
  @inherited_assoc_props = []
end

Instance Method Details

#assoc_propsObject

get attributes with association



62
63
64
65
66
67
68
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 62

def assoc_props
  attributes.select do |attr|
    attr[:association]
  end.map do |attr|
    GeneralizationAttributeDrop.new(attr, upper_klass, name)
  end
end

#attributesObject



33
34
35
36
37
38
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 33

def attributes
  @gen[:general_attributes]
  # @gen[:general_attributes].map do |attr|
  #   GeneralizationAttributeDrop.new(attr, upper_klass, name)
  # end
end

#definitionObject



44
45
46
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 44

def definition
  @gen[:definition]
end

#generalObject



25
26
27
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 25

def general
  GeneralizationDrop.new(@gen[:general]) if @gen[:general]
end

#has_general?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 29

def has_general?
  !!@gen[:general]
end

#idObject



13
14
15
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 13

def id
  @gen[:general_id]
end

#inherited_assoc_propsObject

get items with association by looping through the generation



78
79
80
81
82
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 78

def inherited_assoc_props
  loop_general_item unless @looped_general_item

  @inherited_assoc_props.reverse
end

#inherited_propsObject

get items without association by looping through the generation



71
72
73
74
75
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 71

def inherited_props
  loop_general_item unless @looped_general_item

  @inherited_props.reverse
end

#loop_general_itemObject

rubocop:disable Metrics/MethodLength



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 84

def loop_general_item # rubocop:disable Metrics/MethodLength
  general_item = general
  while general_item.has_general?
    gen_upper_klass = general_item.upper_klass
    gen_name = general_item.name
    # reverse the order to show super class first
    general_item.attributes.reverse_each do |attr|
      attr_drop = GeneralizationAttributeDrop.new(attr, gen_upper_klass,
                                                  gen_name)
      if attr[:association]
        @inherited_assoc_props << attr_drop
      else
        @inherited_props << attr_drop
      end
    end

    general_item = general_item.general
  end

  @looped_general_item = true
end

#nameObject



17
18
19
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 17

def name
  @gen[:general_name]
end

#owned_propsObject

get attributes without association



53
54
55
56
57
58
59
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 53

def owned_props
  attributes.select do |attr|
    attr[:association].nil?
  end.map do |attr|
    GeneralizationAttributeDrop.new(attr, upper_klass, name)
  end
end

#stereotypeObject



48
49
50
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 48

def stereotype
  @gen[:stereotype]
end

#typeObject



40
41
42
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 40

def type
  @gen[:type]
end

#upper_klassObject



21
22
23
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 21

def upper_klass
  @gen[:general_upper_klass]
end