Sha256: e61f5f8d20d221cffc1e3a49505d7b953c9618efbce5d9f69e0c890645aa645b

Contents?: true

Size: 641 Bytes

Versions: 2

Compression:

Stored size: 641 Bytes

Contents

# encoding: utf-8

module Piglet
  module Field
    class Literal
      include Field
    
      def initialize(obj, options=nil)
        options ||= {}
        @obj = obj
        @type = options[:type] || literal_type(obj)
      end
    
      def to_s
        case @obj
        when Numeric
          @obj.to_s
        else
          "'#{escape(@obj.to_s)}'"
        end
      end
      
    private
    
      def literal_type(obj)
        case obj
        when String
          :chararray
        when Integer
          :int
        when Numeric
          :double
        else
          :bytearray
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
piglet-0.3.0 lib/piglet/field/literal.rb
piglet-0.2.5 lib/piglet/field/literal.rb