Sha256: 229bb3c5723195de837918ca760237750a36e15288553d4a4956b8829e15d398

Contents?: true

Size: 751 Bytes

Versions: 1

Compression:

Stored size: 751 Bytes

Contents

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)
      require 'bigdecimal' unless defined?(BigDecimal)
      object = value.object
      object.is_a?(BigDecimal) ? object : BigDecimal.new(object.to_s)
    end

    def self.serialize(value)
      require 'bigdecimal' unless defined?(BigDecimal)
      RDF::Literal.new(value, :datatype => XSD.decimal)
    end

    register_alias XSD.decimal

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spira-0.0.4 lib/spira/types/decimal.rb