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



30
31
32
# File 'lib/sdl/base/property.rb', line 30

def initialize(name, type, parent, multi = false)
  @name, @type, @parent, @multi = name.to_s, type, parent, multi
end

Instance Attribute Details

#holderObject

The type, which currently holds this property



17
18
19
# File 'lib/sdl/base/property.rb', line 17

def holder
  @holder
end

#multiObject (readonly)

Is this Property multi-valued



11
12
13
# File 'lib/sdl/base/property.rb', line 11

def multi
  @multi
end

#nameObject (readonly)

The Property name



5
6
7
# File 'lib/sdl/base/property.rb', line 5

def name
  @name
end

#parentObject (readonly)

The type, for which the property is defined



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

def parent
  @parent
end

#typeObject (readonly)

The Property Type



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

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
# 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|
    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

#multi?Boolean

Is this Property multi-valued

Returns:

  • (Boolean)


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

def multi?
  @multi
end

#single?Boolean

Is this Property single-valued

Returns:

  • (Boolean)


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

def single?
  !@multi
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