Class: OMF::SFA::Model::AbstractPropertyDescription
- Inherits:
-
Base::LObject
- Object
- Base::LObject
- OMF::SFA::Model::AbstractPropertyDescription
- Defined in:
- lib/omf-sfa/model/abstract_prop_description.rb
Direct Known Subclasses
ModelDataPropertyDescription, ModelObjectPropertyDescription
Constant Summary collapse
- @@name2inst =
{}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ns ⇒ Object
readonly
Returns the value of attribute ns.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(full_name) ⇒ AbstractPropertyDescription
constructor
A new instance of AbstractPropertyDescription.
- #parse(cel) ⇒ Object
- #parse_el(node_name, res_name, el) ⇒ Object
- #to_s ⇒ Object
- #validate ⇒ Object
-
#validate_class_reference(ref) ⇒ Object
Return class description for
ref
.
Constructor Details
#initialize(full_name) ⇒ AbstractPropertyDescription
Returns a new instance of AbstractPropertyDescription.
28 29 30 31 32 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 28 def initialize(full_name) @uri = full_name @ns, @name = full_name.split('#') super @name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 26 def name @name end |
#ns ⇒ Object (readonly)
Returns the value of attribute ns.
26 27 28 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 26 def ns @ns end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
26 27 28 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 26 def uri @uri end |
Class Method Details
.create_from_xml(cel) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 14 def self.create_from_xml(cel) about = cel.attribute_with_ns('about', RDF_NS) name = xml_full_name(about.value, cel) klass = @@name2inst[name] ||= self.new(name) klass.parse(cel) klass end |
.each(&block) ⇒ Object
22 23 24 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 22 def self.each(&block) @@name2inst.values.each &block end |
Instance Method Details
#parse(cel) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 57 def parse(cel) cel.children.each do |el| node_name = el.node_name next if node_name == 'comment' attr = el.attribute_with_ns('resource', RDF_NS) res_name = attr ? xml_full_name(attr.value, el) : nil parse_el(node_name, res_name, el) end end |
#parse_el(node_name, res_name, el) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 69 def parse_el(node_name, res_name, el) case node_name when 'range' @range = res_name # ModelClassDescription[res] || raise("Unknonw class '#{res}'") when 'domain' @domain = res_name else warn "Unknown eleement '#{node_name}' in '#{self.class.name}'" end end |
#to_s ⇒ Object
81 82 83 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 81 def to_s "#{@name} (#{self.class.name})" end |
#validate ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 34 def validate() if @domain @domain = validate_class_reference(@domain) @domain.add_property(self) else #warn "No domain reference for property '#{@name}'" end end |
#validate_class_reference(ref) ⇒ Object
Return class description for ref
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/omf-sfa/model/abstract_prop_description.rb', line 45 def validate_class_reference(ref) unless ref.kind_of? ModelClassDescription if ref ref = ModelClassDescription[ref] || raise("Unknonw class '#{ref}'") else raise 'Empty class reference' end end ref end |