Class: Pluggy::PluggyObject::RawNumber

Inherits:
Object
  • Object
show all
Defined in:
lib/pluggy/pluggy_object.rb

Overview

Renders a BigDecimal as an unquoted JSON number.

Instance Method Summary collapse

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_jsonObject



270
# File 'lib/pluggy/pluggy_object.rb', line 270

def to_json(*) = @literal

#to_sObject



271
# File 'lib/pluggy/pluggy_object.rb', line 271

def to_s = @literal