Module: Dcc::TypeGuards
- Defined in:
- lib/dcc/type_guards.rb
Class Method Summary collapse
-
.administrative_data?(node) ⇒ Boolean
True if
nodeis anAdministrativeData(any version). -
.byte_data?(node) ⇒ Boolean
True if
nodeis aByteData(any version). -
.call_if_present(node, method_name, *args) ⇒ Object
Safe method call: invokes the method if the node's class declares it.
-
.core_data?(node) ⇒ Boolean
True if
nodeis aCoreData(any version). -
.digital_calibration_certificate?(node) ⇒ Boolean
True if
nodeis any version of DCC root. -
.has_administrative_data?(node) ⇒ Boolean
True if
nodehas anadministrative_dataattribute (DCC root only). -
.has_attribute?(node, name) ⇒ Boolean
Safe predicate: true if the node has the declared attribute.
-
.has_writer?(node, name) ⇒ Boolean
Safe predicate: true if the node has a writer for the attribute.
-
.measurement_result?(node) ⇒ Boolean
True if
nodeis aMeasurementResult(any version). -
.measurement_result_list?(node) ⇒ Boolean
True if
nodeis aMeasurementResultList(any version). -
.quantity?(node) ⇒ Boolean
True if
nodeis aQuantity(any version). -
.read_attribute(node, name) ⇒ Object
Safe attribute reader: returns the value or nil if the node doesn't have the attribute.
-
.real_list_xml_list?(node) ⇒ Boolean
True if
nodeis aRealListXmlList(any version). -
.resp_person?(node) ⇒ Boolean
True if
nodeis aRespPerson(any version). -
.resp_person_list?(node) ⇒ Boolean
True if
nodeis aRespPersonList(any version). -
.software?(node) ⇒ Boolean
True if
nodeis aSoftware(any version). -
.software_list?(node) ⇒ Boolean
True if
nodeis aSoftwareList(any version). -
.text?(node) ⇒ Boolean
True if
nodeis aText(any version).
Class Method Details
.administrative_data?(node) ⇒ Boolean
True if node is an AdministrativeData (any version).
30 31 32 33 34 |
# File 'lib/dcc/type_guards.rb', line 30 def administrative_data?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::AdministrativeData") end |
.byte_data?(node) ⇒ Boolean
True if node is a ByteData (any version).
93 94 95 96 97 |
# File 'lib/dcc/type_guards.rb', line 93 def byte_data?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::ByteData") end |
.call_if_present(node, method_name, *args) ⇒ Object
Safe method call: invokes the method if the node's class declares it.
133 134 135 136 137 138 |
# File 'lib/dcc/type_guards.rb', line 133 def call_if_present(node, method_name, *args) return nil unless node.is_a?(::Lutaml::Model::Serializable) return nil unless node.class.attributes.key?(method_name) node.public_send(method_name, *args) end |
.core_data?(node) ⇒ Boolean
True if node is a CoreData (any version).
37 38 39 40 41 |
# File 'lib/dcc/type_guards.rb', line 37 def core_data?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::CoreData") end |
.digital_calibration_certificate?(node) ⇒ Boolean
True if node is any version of DCC root.
11 12 13 14 15 |
# File 'lib/dcc/type_guards.rb', line 11 def digital_calibration_certificate?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::DigitalCalibrationCertificate") end |
.has_administrative_data?(node) ⇒ Boolean
True if node has an administrative_data attribute (DCC root only).
18 19 20 |
# File 'lib/dcc/type_guards.rb', line 18 def has_administrative_data?(node) digital_calibration_certificate?(node) end |
.has_attribute?(node, name) ⇒ Boolean
Safe predicate: true if the node has the declared attribute.
Replaces node.respond_to?(:name).
118 119 120 121 122 |
# File 'lib/dcc/type_guards.rb', line 118 def has_attribute?(node, name) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.attributes.key?(name) end |
.has_writer?(node, name) ⇒ Boolean
Safe predicate: true if the node has a writer for the attribute.
Replaces node.respond_to?(:name=).
126 127 128 129 130 |
# File 'lib/dcc/type_guards.rb', line 126 def has_writer?(node, name) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.attributes.key?(name) end |
.measurement_result?(node) ⇒ Boolean
True if node is a MeasurementResult (any version).
86 87 88 89 90 |
# File 'lib/dcc/type_guards.rb', line 86 def measurement_result?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::MeasurementResult") end |
.measurement_result_list?(node) ⇒ Boolean
True if node is a MeasurementResultList (any version).
23 24 25 26 27 |
# File 'lib/dcc/type_guards.rb', line 23 def measurement_result_list?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::MeasurementResultList") end |
.quantity?(node) ⇒ Boolean
True if node is a Quantity (any version).
100 101 102 103 104 |
# File 'lib/dcc/type_guards.rb', line 100 def quantity?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::Quantity") end |
.read_attribute(node, name) ⇒ Object
Safe attribute reader: returns the value or nil if the node doesn't
have the attribute. Uses explicit class introspection rather than
respond_to?.
109 110 111 112 113 114 |
# File 'lib/dcc/type_guards.rb', line 109 def read_attribute(node, name) return nil unless node.is_a?(::Lutaml::Model::Serializable) return nil unless node.class.attributes.key?(name) node.public_send(name) end |
.real_list_xml_list?(node) ⇒ Boolean
True if node is a RealListXmlList (any version).
72 73 74 75 76 |
# File 'lib/dcc/type_guards.rb', line 72 def real_list_xml_list?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::RealListXmlList") end |
.resp_person?(node) ⇒ Boolean
True if node is a RespPerson (any version).
51 52 53 54 55 |
# File 'lib/dcc/type_guards.rb', line 51 def resp_person?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::RespPerson") end |
.resp_person_list?(node) ⇒ Boolean
True if node is a RespPersonList (any version).
44 45 46 47 48 |
# File 'lib/dcc/type_guards.rb', line 44 def resp_person_list?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::RespPersonList") end |
.software?(node) ⇒ Boolean
True if node is a Software (any version).
65 66 67 68 69 |
# File 'lib/dcc/type_guards.rb', line 65 def software?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::Software") end |
.software_list?(node) ⇒ Boolean
True if node is a SoftwareList (any version).
58 59 60 61 62 |
# File 'lib/dcc/type_guards.rb', line 58 def software_list?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::SoftwareList") end |
.text?(node) ⇒ Boolean
True if node is a Text (any version).
79 80 81 82 83 |
# File 'lib/dcc/type_guards.rb', line 79 def text?(node) return false unless node.is_a?(::Lutaml::Model::Serializable) node.class.name.end_with?("::Text") end |