Class: SDL::Base::Property

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#holderClass

The type, which currently holds this property

Returns:

  • (Class)


32
33
34
# File 'lib/sdl/base/property.rb', line 32

def holder
  @holder
end

#multiBoolean (readonly)

Is this Property multi-valued

Returns:

  • (Boolean)


20
21
22
# File 'lib/sdl/base/property.rb', line 20

def multi
  @multi
end

#nameString (readonly)

The Property name

Returns:

  • (String)


8
9
10
# File 'lib/sdl/base/property.rb', line 8

def name
  @name
end

#parentClass (readonly)

The type, for which the property is defined

Returns:

  • (Class)


26
27
28
# File 'lib/sdl/base/property.rb', line 26

def parent
  @parent
end

#typeClass (readonly)

The Property Type

Returns:

  • (Class)


14
15
16
# File 'lib/sdl/base/property.rb', line 14

def type
  @type
end

Instance Method Details

#documentation_keyObject

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?

Returns:

  • (Boolean)


51
52
53
# File 'lib/sdl/base/property.rb', line 51

def inherited?
  ! parent.eql? holder
end

#multi?Boolean

Is this Property multi-valued

Returns:

  • (Boolean)


44
45
46
# File 'lib/sdl/base/property.rb', line 44

def multi?
  @multi
end

#simple_type?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


37
38
39
# File 'lib/sdl/base/property.rb', line 37

def single?
  !@multi
end

#to_sObject



64
65
66
# File 'lib/sdl/base/property.rb', line 64

def to_s
  "#{@parent.original_name}.#{@name.to_s}"
end

#xsd_element_nameObject



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