Class: HyperCast::NumFormat
- Inherits:
-
Data
- Object
- Data
- HyperCast::NumFormat
- Defined in:
- lib/hypercast.rb
Overview
Caller-declared numeric notation for the integer and real doors — declared out loud (INVARIANT, or a literal), never defaulted, the same stance every binding takes. Equal separators are a caller bug (ArgumentError), never a verdict.
Constant Summary collapse
- INVARIANT =
The invariant profile — '.' decimal, ',' grouping, every lenience on.
NumFormat.new(decimal_sep: ".", group_sep: ",", flags: ALL_STYLES)
- DETECT =
The detection profile — every lenience on, ./, roles resolved per input by SEPARATOR_DETECT's structural rules.
NumFormat.new(decimal_sep: ".", group_sep: ",", flags: ALL_STYLES | SEPARATOR_DETECT)
Instance Attribute Summary collapse
-
#decimal_sep ⇒ Object
readonly
Returns the value of attribute decimal_sep.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#group_sep ⇒ Object
readonly
Returns the value of attribute group_sep.
Instance Method Summary collapse
-
#initialize(decimal_sep:, group_sep:, flags:) ⇒ NumFormat
constructor
Validates the declared separators up front — single characters, and distinct from each other — so a malformed format fails loudly as the caller bug it is.
-
#packed ⇒ Object
The 12-byte little-endian form the native ABI's NumFormat struct expects.
Constructor Details
#initialize(decimal_sep:, group_sep:, flags:) ⇒ NumFormat
Validates the declared separators up front — single characters, and distinct from each other — so a malformed format fails loudly as the caller bug it is.
45 46 47 48 49 50 51 52 |
# File 'lib/hypercast.rb', line 45 def initialize(decimal_sep:, group_sep:, flags:) raise ArgumentError, "separators must be single characters" unless decimal_sep.is_a?(String) && decimal_sep.length == 1 && group_sep.is_a?(String) && group_sep.length == 1 raise ArgumentError, "decimal and group separators must differ; both are #{decimal_sep.inspect}" if decimal_sep == group_sep super end |
Instance Attribute Details
#decimal_sep ⇒ Object (readonly)
Returns the value of attribute decimal_sep
42 43 44 |
# File 'lib/hypercast.rb', line 42 def decimal_sep @decimal_sep end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags
42 43 44 |
# File 'lib/hypercast.rb', line 42 def flags @flags end |
#group_sep ⇒ Object (readonly)
Returns the value of attribute group_sep
42 43 44 |
# File 'lib/hypercast.rb', line 42 def group_sep @group_sep end |
Instance Method Details
#packed ⇒ Object
The 12-byte little-endian form the native ABI's NumFormat struct expects.
55 56 57 |
# File 'lib/hypercast.rb', line 55 def packed [decimal_sep.ord, group_sep.ord, flags].pack("L<L<L<") end |