Sha256: db3a60caeadc1f8019bd5a2374e98ea7549840ec811d0e541a767396d8e95fca

Contents?: true

Size: 722 Bytes

Versions: 10

Compression:

Stored size: 722 Bytes

Contents

require 'bigdecimal'

module Spira::Types

  ##
  # A {Spira::Type} for integer values.  Values will be associated with the
  # `XSD.integer` type.
  #
  # A {Spira::Resource} property can reference this type as
  # `Spira::Types::Integer`, `Integer`, or `XSD.integer`.
  #
  # @see Spira::Type
  # @see http://rdf.rubyforge.org/RDF/Literal.html
  class Decimal
    include Spira::Type

    def self.unserialize(value)
      object = value.object
      object.is_a?(BigDecimal) ? object : BigDecimal.new(object.to_s)
    end

    def self.serialize(value)
      RDF::Literal.new(value.is_a?(BigDecimal) ? value.to_s('F') : value.to_s, :datatype => RDF::XSD.decimal)
    end

    register_alias RDF::XSD.decimal

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spira-3.1.0 lib/spira/types/decimal.rb
spira-3.0.0 lib/spira/types/decimal.rb
spira-2.1.0 lib/spira/types/decimal.rb
spira-2.0.2 lib/spira/types/decimal.rb
spira-2.0.1 lib/spira/types/decimal.rb
spira-2.0.0 lib/spira/types/decimal.rb
spira-1.1.1 lib/spira/types/decimal.rb
spira-0.7.1 lib/spira/types/decimal.rb
spira-0.7 lib/spira/types/decimal.rb
spira-0.5.0 lib/spira/types/decimal.rb