Class: SDL::Base::Property
- Inherits:
-
Object
- Object
- SDL::Base::Property
- Defined in:
- lib/sdl/base/property.rb,
lib/sdl/util/documentation.rb,
lib/sdl/exporters/xml_mapping.rb
Overview
A property of a Fact or Type. It has a #name and an associated Type.
Instance Attribute Summary collapse
-
#holder ⇒ Class
The type, which currently holds this property.
-
#multi ⇒ Boolean
readonly
Is this Property multi-valued.
-
#name ⇒ String
readonly
The Property name.
-
#parent ⇒ Class
readonly
The type, for which the property is defined.
-
#type ⇒ Class
readonly
The Property Type.
Instance Method Summary collapse
-
#documentation_key ⇒ Object
As properties are inherited, the documentation could either be defined by the current type, or any subtypes, which also define or inherit this key.
-
#inherited? ⇒ Boolean
Was this property inherited from one of its parents?.
-
#initialize(name, type, parent, multi = false) ⇒ Property
constructor
Define a property by its name and type.
-
#multi? ⇒ Boolean
Is this Property multi-valued.
- #simple_type? ⇒ Boolean
-
#single? ⇒ Boolean
Is this Property single-valued.
- #to_s ⇒ Object
- #xsd_element_name ⇒ Object
Constructor Details
#initialize(name, type, parent, multi = false) ⇒ Property
Define a property by its name and type
60 61 62 |
# File 'lib/sdl/base/property.rb', line 60 def initialize(name, type, parent, multi = false) @name, @type, @parent, @multi = name.to_s, type, parent, multi end |
Instance Attribute Details
#holder ⇒ Class
The type, which currently holds this property
32 33 34 |
# File 'lib/sdl/base/property.rb', line 32 def holder @holder end |
#multi ⇒ Boolean (readonly)
Is this Property multi-valued
20 21 22 |
# File 'lib/sdl/base/property.rb', line 20 def multi @multi end |
#name ⇒ String (readonly)
The Property name
8 9 10 |
# File 'lib/sdl/base/property.rb', line 8 def name @name end |
#parent ⇒ Class (readonly)
The type, for which the property is defined
26 27 28 |
# File 'lib/sdl/base/property.rb', line 26 def parent @parent end |
#type ⇒ Class (readonly)
The Property Type
14 15 16 |
# File 'lib/sdl/base/property.rb', line 14 def type @type end |
Instance Method Details
#documentation_key ⇒ Object
As properties are inherited, the documentation could either be defined by the current type, or any subtypes, which also define or inherit this key. This method finds the first defined key.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/sdl/util/documentation.rb', line 85 def documentation_key # Search class and ancestors, if any defines a documentation key @holder.ancestors.each do |ancestor| next if (ancestor <=> SDL::Base::Type) == nil break if ancestor.eql?(SDL::Base::Type) || ancestor.eql?(SDL::Types::SDLType) key = "sdl.property.#{SDL::Util::Documentation.walk_the_class_name(ancestor)}.#{@name}" return key if I18n.exists? key end # Return default key return "sdl.property.#{SDL::Util::Documentation.walk_the_class_name(@parent)}.#{@name}" end |
#inherited? ⇒ Boolean
Was this property inherited from one of its parents?
51 52 53 |
# File 'lib/sdl/base/property.rb', line 51 def inherited? ! parent.eql? holder end |
#multi? ⇒ Boolean
Is this Property multi-valued
44 45 46 |
# File 'lib/sdl/base/property.rb', line 44 def multi? @multi end |
#simple_type? ⇒ Boolean
55 56 57 |
# File 'lib/sdl/base/property.rb', line 55 def simple_type? type <= SDL::Types::SDLSimpleType end |
#single? ⇒ Boolean
Is this Property single-valued
37 38 39 |
# File 'lib/sdl/base/property.rb', line 37 def single? !@multi end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/sdl/base/property.rb', line 64 def to_s "#{@parent.original_name}.#{@name.to_s}" end |
#xsd_element_name ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/sdl/exporters/xml_mapping.rb', line 4 def xsd_element_name if multi? @name.singularize else @name end end |