Sha256: b6a67c1a82b6fe09f93b27eb5638095e3c84113de28df5f75a2d2b43fa59a856

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

module Jaspion
  module Kilza
    # Represents a single Class property
    class Property
      # Normalized property name
      # Starts with _ or alphanumeric character
      # and doesn't contain any special character
      attr_accessor :name

      # Original JSON property name
      attr_accessor :original_name

      # Ruby string type
      # Can be object, fixnum, float, falseclass, trueclass and nilclass
      attr_accessor :original_type

      # Property type name
      attr_accessor :type

      # Indicates if the property represents an array of objects
      attr_accessor :array
      alias_method :array?, :array

      # Indicates if the property should be used for comparing purposes
      # Used to compare if one object is equal to another one
      attr_accessor :key
      alias_method :key?, :key

      def initialize(name, type, array, key)
        @name = Kilza.normalize(name)
        @original_name = name
        @type = type
        @array = array
        @key = key
        @original_type = type
      end

      def object?
        @original_type == 'hash'
      end

      def fixnum?
        @original_type == 'fixnum'
      end

      def boolean?
        @original_type == 'trueclass' || @original_type == 'falseclass'
      end

      def float?
        @original_type == 'float'
      end

      def null?
        @original_type == 'nilclass'
      end

      def ==(pr)
        @name == pr.name
      end

      def to_s
        {
          name: @name,
          original_name: @original_name,
          type: @type,
          array?: @array
        }.to_s
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jaspion-kilza-1.1.1 lib/jaspion/kilza/property.rb
jaspion-kilza-1.1.0 lib/jaspion/kilza/property.rb
jaspion-kilza-1.0.9 lib/jaspion/kilza/property.rb
jaspion-kilza-1.0.8 lib/jaspion/kilza/property.rb