Class: SDL::Base::Type
- Inherits:
-
Object
- Object
- SDL::Base::Type
- 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
Class Attribute Summary collapse
-
.list_item ⇒ Object
If the Type is a list item type.
-
.namespace ⇒ Object
The namespace URL of this Type class.
Instance Attribute Summary collapse
-
#identifier ⇒ Object
An identifier for type instances.
-
#parent ⇒ Object
The parent of this type.
-
#parent_index ⇒ Object
The index of this type instance in the parent list.
Class Method Summary collapse
- .documentation_key ⇒ Object
- .is_sub? ⇒ Boolean
- .list_item? ⇒ Boolean
- .local_name ⇒ Object
- .local_name=(name) ⇒ Object
- .multi_property?(including_super = true) ⇒ Boolean
- .properties(including_super = false) ⇒ Object
- .propertyless?(including_super = true) ⇒ Boolean
- .single_property(including_super = true) ⇒ Object
- .single_property?(including_super = true) ⇒ Boolean
- .to_s ⇒ Object
- .xsd_element_name ⇒ Object
- .xsd_type_name ⇒ Object
Instance Method Summary collapse
- #annotated? ⇒ Boolean
- #annotations ⇒ Object
- #documentation_key ⇒ Object
-
#property_values(include_empty = true) ⇒ Object
Gets the values of all properties.
- #rdf_object ⇒ Object
- #to_s ⇒ Object
Methods included from URIMappedResource
Class Attribute Details
.list_item ⇒ Object
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 |
.namespace ⇒ Object
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
#identifier ⇒ Object
An identifier for type instances
100 101 102 |
# File 'lib/sdl/base/type.rb', line 100 def identifier @identifier end |
#parent ⇒ Object
The parent of this type.
106 107 108 |
# File 'lib/sdl/base/type.rb', line 106 def parent @parent end |
#parent_index ⇒ Object
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_key ⇒ Object
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
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
59 60 61 |
# File 'lib/sdl/base/type.rb', line 59 def list_item? @list_item == true end |
.local_name ⇒ Object
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
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
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
47 48 49 |
# File 'lib/sdl/base/type.rb', line 47 def single_property?(including_super = true) properties(including_super).count == 1 end |
.to_s ⇒ Object
27 28 29 |
# File 'lib/sdl/base/type.rb', line 27 def to_s @local_name || name end |
.xsd_element_name ⇒ Object
15 16 17 |
# File 'lib/sdl/exporters/xml_mapping.rb', line 15 def xsd_element_name local_name.camelize(:lower) end |
.xsd_type_name ⇒ Object
19 20 21 |
# File 'lib/sdl/exporters/xml_mapping.rb', line 19 def xsd_type_name local_name end |
Instance Method Details
#annotated? ⇒ Boolean
91 92 93 |
# File 'lib/sdl/base/type.rb', line 91 def annotated? ! @annotations.blank? end |
#annotations ⇒ Object
95 96 97 |
# File 'lib/sdl/base/type.rb', line 95 def annotations @annotations ||= [] end |
#documentation_key ⇒ Object
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_object ⇒ Object
12 13 14 |
# File 'lib/sdl/exporters/rdf_mapping.rb', line 12 def rdf_object RDF::URI.new(uri) end |
#to_s ⇒ Object
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 |