Class: Opencdd::RelationType
- Inherits:
-
Object
- Object
- Opencdd::RelationType
- Defined in:
- lib/opencdd/relation_type.rb
Constant Summary collapse
- VALUES =
%w[ PREDICATION FUNCTION ASSOCIATION AGGREGATION COMPOSITION GENERALIZATION SPECIALIZATION ].freeze
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #aggregation? ⇒ Boolean
- #association? ⇒ Boolean
- #composition? ⇒ Boolean
- #function? ⇒ Boolean
- #generalization? ⇒ Boolean
- #hash ⇒ Object
- #hierarchical? ⇒ Boolean
-
#initialize(value) ⇒ RelationType
constructor
A new instance of RelationType.
- #predication? ⇒ Boolean
- #specialization? ⇒ Boolean
- #to_s ⇒ Object (also: #inspect)
- #to_sym ⇒ Object
Constructor Details
#initialize(value) ⇒ RelationType
Returns a new instance of RelationType.
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
#value ⇒ Object (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
21 |
# File 'lib/opencdd/relation_type.rb', line 21 def aggregation? = @value == "AGGREGATION" |
#association? ⇒ Boolean
20 |
# File 'lib/opencdd/relation_type.rb', line 20 def association? = @value == "ASSOCIATION" |
#composition? ⇒ Boolean
22 |
# File 'lib/opencdd/relation_type.rb', line 22 def composition? = @value == "COMPOSITION" |
#function? ⇒ Boolean
19 |
# File 'lib/opencdd/relation_type.rb', line 19 def function? = @value == "FUNCTION" |
#generalization? ⇒ Boolean
23 |
# File 'lib/opencdd/relation_type.rb', line 23 def generalization? = @value == "GENERALIZATION" |
#hash ⇒ Object
38 39 40 |
# File 'lib/opencdd/relation_type.rb', line 38 def hash @value.hash end |
#hierarchical? ⇒ Boolean
26 27 28 |
# File 'lib/opencdd/relation_type.rb', line 26 def hierarchical? generalization? || specialization? || aggregation? || composition? end |
#predication? ⇒ Boolean
18 |
# File 'lib/opencdd/relation_type.rb', line 18 def predication? = @value == "PREDICATION" |
#specialization? ⇒ Boolean
24 |
# File 'lib/opencdd/relation_type.rb', line 24 def specialization? = @value == "SPECIALIZATION" |
#to_s ⇒ Object Also known as: inspect
30 |
# File 'lib/opencdd/relation_type.rb', line 30 def to_s = @value |
#to_sym ⇒ Object
31 |
# File 'lib/opencdd/relation_type.rb', line 31 def to_sym = @value.downcase.to_sym |