Class: Opencdd::RelationType

Inherits:
Object
  • Object
show all
Defined in:
lib/opencdd/relation_type.rb

Constant Summary collapse

VALUES =
%w[
  PREDICATION FUNCTION ASSOCIATION AGGREGATION COMPOSITION
  GENERALIZATION SPECIALIZATION
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ RelationType

Returns a new instance of RelationType.

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/opencdd/relation_type.rb', line 12

def initialize(value)
  v = value.to_s.strip.upcase
  raise ArgumentError, "unknown relation type: #{value.inspect}" unless VALUES.include?(v)
  @value = v
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/opencdd/relation_type.rb', line 10

def value
  @value
end

Class Method Details

.parse(raw) ⇒ Object



44
45
46
47
48
49
# File 'lib/opencdd/relation_type.rb', line 44

def self.parse(raw)
  return nil if raw.nil? || raw.to_s.strip.empty?
  s = raw.to_s.strip.upcase
  return nil unless VALUES.include?(s)
  new(s)
end

.parse_or_symbol(raw) ⇒ Object



51
52
53
54
55
56
# File 'lib/opencdd/relation_type.rb', line 51

def self.parse_or_symbol(raw)
  parsed = parse(raw)
  return parsed if parsed
  return nil if raw.nil? || raw.to_s.strip.empty?
  raw.to_s.strip.upcase.to_sym
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



33
34
35
# File 'lib/opencdd/relation_type.rb', line 33

def ==(other)
  other.is_a?(Opencdd::RelationType) && @value == other.value
end

#aggregation?Boolean

Returns:

  • (Boolean)


21
# File 'lib/opencdd/relation_type.rb', line 21

def aggregation?    = @value == "AGGREGATION"

#association?Boolean

Returns:

  • (Boolean)


20
# File 'lib/opencdd/relation_type.rb', line 20

def association?    = @value == "ASSOCIATION"

#composition?Boolean

Returns:

  • (Boolean)


22
# File 'lib/opencdd/relation_type.rb', line 22

def composition?    = @value == "COMPOSITION"

#function?Boolean

Returns:

  • (Boolean)


19
# File 'lib/opencdd/relation_type.rb', line 19

def function?       = @value == "FUNCTION"

#generalization?Boolean

Returns:

  • (Boolean)


23
# File 'lib/opencdd/relation_type.rb', line 23

def generalization? = @value == "GENERALIZATION"

#hashObject



38
39
40
# File 'lib/opencdd/relation_type.rb', line 38

def hash
  @value.hash
end

#hierarchical?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/opencdd/relation_type.rb', line 26

def hierarchical?
  generalization? || specialization? || aggregation? || composition?
end

#predication?Boolean

Returns:

  • (Boolean)


18
# File 'lib/opencdd/relation_type.rb', line 18

def predication?    = @value == "PREDICATION"

#specialization?Boolean

Returns:

  • (Boolean)


24
# File 'lib/opencdd/relation_type.rb', line 24

def specialization? = @value == "SPECIALIZATION"

#to_sObject Also known as: inspect



30
# File 'lib/opencdd/relation_type.rb', line 30

def to_s   = @value

#to_symObject



31
# File 'lib/opencdd/relation_type.rb', line 31

def to_sym = @value.downcase.to_sym