Module: Dcc::TypeGuards

Defined in:
lib/dcc/type_guards.rb

Class Method Summary collapse

Class Method Details

.administrative_data?(node) ⇒ Boolean

True if node is an AdministrativeData (any version).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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=).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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