Class: Reqif::ReqifInteger

Inherits:
Lutaml::Model::Type::Decimal
  • Object
show all
Defined in:
lib/reqif/reqif_integer.rb

Overview

Custom Integer type using BigDecimal internally to support arbitrary precision integers beyond Ruby’s native 64-bit range. Serializes without a decimal point for ReqIF compatibility.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cast(value, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/reqif/reqif_integer.rb', line 11

def self.cast(value, options = {})
  return nil if value.nil?

  result = super
  return nil if result.nil?

  result
end

.to_xml(value) ⇒ Object

Serialize to XML as a plain integer (no decimal point, no fractional part). Uses BigDecimal#to_i to strip any fractional part, ensuring output matches ReqIF’s integer format.



23
24
25
26
27
28
29
30
# File 'lib/reqif/reqif_integer.rb', line 23

def self.to_xml(value)
  return nil if value.nil?

  result = cast(value)
  return nil if result.nil?

  result.to_i.to_s
end

Instance Method Details

#to_xmlObject



32
33
34
# File 'lib/reqif/reqif_integer.rb', line 32

def to_xml
  self.class.to_xml(value)
end