zipdatev 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b14ed5e1f68c6aae3b564a967bc36dd5ff0d4fdec083d682452161ceb565bcd
4
- data.tar.gz: 6c98b7e93719825e69ef0c0483134a256c864fbb734978cc5102f4b7272b82fe
3
+ metadata.gz: 93a524d3a6c114e4ba449add730c39e4db83007ff043ef1b0e734786b4f56c1f
4
+ data.tar.gz: be5eb61e54fb13aca8fc308286c6ca02b5302f1663217b5470770e4e7fe786be
5
5
  SHA512:
6
- metadata.gz: ff15c712b6e8661f54f28b5ac32f9d575e160d5973e8c43dd2330bebe174c1b430457ad20f6d8695e39c79299f87f6937cfcc81142416cc07ac09105ea443ea2
7
- data.tar.gz: 8b9ff68c49b67c4059797ccc73bd68bc66a28299cafae8ad8b5b18a16f9634f85ee2b404cf5c58bade0ab42df38d2ef1314513dd7e34169f4320bb4a650d2126
6
+ metadata.gz: 3637481aa9773fcdc5458ecbdced141d9fa817fc6098df825b6e395fcee5fa0f92ce33ab18d6bef5d8d499f037a19f691f5f4873b44bee233c4280393c6c973b
7
+ data.tar.gz: 87d7e721150ac9771e7ec9bc20d1c7a2569a2c9736cd30ff9b8b071e269571b30f8c8dda538436155b06f54d0eb1889523fb09ed8adbd85d06cadb8fa806148e
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bigdecimal"
3
4
  require "nokogiri"
4
5
  require "active_support/core_ext/string/inflections"
5
6
 
@@ -82,13 +83,19 @@ module ZipDatev
82
83
 
83
84
  # Format a decimal value for XML output with specified precision
84
85
  #
86
+ # Uses BigDecimal's string representation to avoid floating point artifacts
87
+ # from format()/sprintf(), which implicitly convert BigDecimal to Float.
88
+ #
85
89
  # @param value [BigDecimal, Numeric, nil] The value to format
86
90
  # @param precision [Integer] Number of decimal places (default: 2)
87
91
  # @return [String, nil] Formatted decimal string or nil if value is nil
88
92
  def format_decimal(value, precision: 2)
89
93
  return nil if value.nil?
90
94
 
91
- format("%.#{precision}f", value)
95
+ decimal = value.is_a?(BigDecimal) ? value : BigDecimal(value.to_s)
96
+ str = decimal.round(precision).to_s("F")
97
+ integer_part, fractional_part = str.split(".")
98
+ "#{integer_part}.#{(fractional_part || "").ljust(precision, "0")}"
92
99
  end
93
100
 
94
101
  # Convert a Ruby snake_case symbol to XML camelCase element name
@@ -36,9 +36,9 @@ class DecimalPrecisionValidator < ActiveModel::EachValidator
36
36
  # Convert to BigDecimal for consistent handling
37
37
  decimal = value.is_a?(BigDecimal) ? value : BigDecimal(value.to_s)
38
38
 
39
- # Use string representation to check decimal places
40
- # Format with many decimal places to avoid rounding
41
- str = format("%.#{places + 10}f", decimal)
39
+ # Use BigDecimal's string representation to avoid floating point artifacts
40
+ # BigDecimal#to_s("F") returns a fixed-point string like "12691.72"
41
+ str = decimal.to_s("F")
42
42
  parts = str.split(".")
43
43
 
44
44
  return places.zero? if parts.length == 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZipDatev
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipdatev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dexter Team