Class: Pluggy::PluggyObject::RawNumber
- Inherits:
-
Object
- Object
- Pluggy::PluggyObject::RawNumber
- Defined in:
- lib/pluggy/pluggy_object.rb
Overview
Renders a BigDecimal as an unquoted JSON number.
Instance Method Summary collapse
-
#initialize(decimal) ⇒ RawNumber
constructor
A new instance of RawNumber.
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(decimal) ⇒ RawNumber
Returns a new instance of RawNumber.
263 264 265 266 267 268 |
# File 'lib/pluggy/pluggy_object.rb', line 263 def initialize(decimal) # "F" gives "-212.45" rather than "-0.21245e3". @literal = decimal.to_s("F") # Trim the trailing ".0" BigDecimal adds to integral values. @literal = @literal.sub(/\.0\z/, "") end |
Instance Method Details
#to_json ⇒ Object
270 |
# File 'lib/pluggy/pluggy_object.rb', line 270 def to_json(*) = @literal |
#to_s ⇒ Object
271 |
# File 'lib/pluggy/pluggy_object.rb', line 271 def to_s = @literal |