Class: SDL::Base::Type

Inherits:
Object
  • Object
show all
Extended by:
URIMappedResource
Includes:
URIMappedResource
Defined in:
lib/sdl/base/type.rb,
lib/sdl/util/documentation.rb,
lib/sdl/exporters/rdf_mapping.rb,
lib/sdl/exporters/xml_mapping.rb

Direct Known Subclasses

Fact

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from URIMappedResource

uri

Class Attribute Details

.list_itemObject

If the Type is a list item type



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

def list_item
  @list_item
end

.namespaceObject

The namespace URL of this Type class



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

def namespace
  @namespace
end

Instance Attribute Details

#identifierObject

An identifier for type instances



100
101
102
# File 'lib/sdl/base/type.rb', line 100

def identifier
  @identifier
end

#parentObject

The parent of this type.



106
107
108
# File 'lib/sdl/base/type.rb', line 106

def parent
  @parent
end

#parent_indexObject

The index of this type instance in the parent list



103
104
105
# File 'lib/sdl/base/type.rb', line 103

def parent_index
  @parent_index
end

Class Method Details

.documentation_keyObject



72
73
74
# File 'lib/sdl/util/documentation.rb', line 72

def self.documentation_key
  "sdl.#{SDL::Util::Documentation.walk_the_class_name(self)}"
end

.is_sub?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/sdl/base/type.rb', line 63

def is_sub?
  not [SDL::Base::Type, SDL::Base::Fact].include? superclass
end

.list_item?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/sdl/base/type.rb', line 59

def list_item?
  @list_item == true
end

.local_nameObject



19
20
21
# File 'lib/sdl/base/type.rb', line 19

def local_name
  @local_name || name.demodulize
end

.local_name=(name) ⇒ Object



23
24
25
# File 'lib/sdl/base/type.rb', line 23

def local_name=(name)
  @local_name = name
end

.multi_property?(including_super = true) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/sdl/base/type.rb', line 55

def multi_property?(including_super = true)
  properties(including_super).count > 1
end

.properties(including_super = false) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sdl/base/type.rb', line 31

def properties(including_super = false)
  if including_super && is_sub?
    retrieved_properties = self.properties + superclass.properties(true)
  else
    retrieved_properties = @properties ||= []
  end

  retrieved_properties.each do |p|
    p.holder = self
  end
end

.propertyless?(including_super = true) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/sdl/base/type.rb', line 43

def propertyless?(including_super = true)
  properties(including_super).count == 0
end

.single_property(including_super = true) ⇒ Object



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

def single_property(including_super = true)
  properties(including_super).first
end

.single_property?(including_super = true) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/sdl/base/type.rb', line 47

def single_property?(including_super = true)
  properties(including_super).count == 1
end

.to_sObject



27
28
29
# File 'lib/sdl/base/type.rb', line 27

def to_s
  @local_name || name
end

.xsd_element_nameObject



15
16
17
# File 'lib/sdl/exporters/xml_mapping.rb', line 15

def xsd_element_name
  local_name.camelize(:lower)
end

.xsd_type_nameObject



19
20
21
# File 'lib/sdl/exporters/xml_mapping.rb', line 19

def xsd_type_name
  local_name
end

Instance Method Details

#annotated?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/sdl/base/type.rb', line 91

def annotated?
  ! @annotations.blank?
end

#annotationsObject



95
96
97
# File 'lib/sdl/base/type.rb', line 95

def annotations
  @annotations ||= []
end

#documentation_keyObject



76
77
78
# File 'lib/sdl/util/documentation.rb', line 76

def documentation_key
  "sdl.instance.#{SDL::Util::Documentation.walk_the_class_name(self.class)}.#{@identifier}"
end

#property_values(include_empty = true) ⇒ Object

Gets the values of all properties



70
71
72
73
74
75
76
77
78
# File 'lib/sdl/base/type.rb', line 70

def property_values(include_empty = true)
  pv = Hash[self.class.properties(true).map{|p| [p, send(p.name)]}]

  unless include_empty
    pv.reject! {|p, v| v.blank? }
  end

  pv
end

#rdf_objectObject



12
13
14
# File 'lib/sdl/exporters/rdf_mapping.rb', line 12

def rdf_object
  RDF::URI.new(uri)
end

#to_sObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/sdl/base/type.rb', line 80

def to_s
  # If there is a property with the same name, than the type, return its to_s, return the name of the class

  naming_property = self.class.properties(true).find {|p| p.name.eql?(self.class.to_s.underscore) }

  if(naming_property)
    instance_variable_get("@#{naming_property.name.to_sym}").to_s
  else
    self.class.to_s
  end
end