class Jaspion::Kilza::Property

Represents a single Class property

Attributes

array[RW]

Indicates if the property represents an array of objects

array?[RW]

Indicates if the property represents an array of objects

key[RW]

Indicates if the property should be used for comparing purposes Used to compare if one object is equal to another one

key?[RW]

Indicates if the property should be used for comparing purposes Used to compare if one object is equal to another one

name[RW]

Normalized property name Starts with _ or alphanumeric character and doesn't contain any special character

original_name[RW]

Original JSON property name

original_type[RW]

Ruby string type Can be object, fixnum, float, falseclass, trueclass and nilclass

type[RW]

Property type name

Public Class Methods

clean(str) click to toggle source

Removes everything except numbers and letters.

@param str [String] string to be cleaned

@return [String] cleaned string

# File lib/jaspion/kilza/property.rb, line 82
def self.clean(str)
  return if str.nil?
  str.gsub(/[^a-zA-Z0-9]/, '')
end
new(name, type, array, key = '') click to toggle source
# File lib/jaspion/kilza/property.rb, line 29
def initialize(name, type, array, key = '')
  @name = Jaspion::Kilza::Property.normalize(name)
  @original_name = name
  @type = type
  @array = array
  @key = key
  @original_type = type
end
normalize(str) click to toggle source

Cleans the string and make it lowercase.

@param str [String] string to be cleaned

@return [String] cleaned string

# File lib/jaspion/kilza/property.rb, line 92
def self.normalize(str)
  return if str.nil?
  str = str.gsub(/[^a-zA-Z0-9]/, '_')
  str = '_' if str.length == 0
  str = '_' + str if str[0].number?
  str.downcase
end

Public Instance Methods

==(pr) click to toggle source
# File lib/jaspion/kilza/property.rb, line 58
def ==(pr)
  @name == pr.name
end
boolean?() click to toggle source
# File lib/jaspion/kilza/property.rb, line 46
def boolean?
  @original_type == 'trueclass' || @original_type == 'falseclass'
end
class_name() click to toggle source

If this Property represents a new Class, it returns the formatted class name

# File lib/jaspion/kilza/property.rb, line 64
def class_name
  Jaspion::Kilza::Class.normalize(@original_name)
end
fixnum?() click to toggle source
# File lib/jaspion/kilza/property.rb, line 42
def fixnum?
  @original_type == 'fixnum'
end
float?() click to toggle source
# File lib/jaspion/kilza/property.rb, line 50
def float?
  @original_type == 'float'
end
null?() click to toggle source
# File lib/jaspion/kilza/property.rb, line 54
def null?
  @original_type == 'nilclass'
end
object?() click to toggle source
# File lib/jaspion/kilza/property.rb, line 38
def object?
  @original_type == 'hash'
end
to_s() click to toggle source
# File lib/jaspion/kilza/property.rb, line 68
def to_s
  {
    name: @name,
    original_name: @original_name,
    type: @type,
    array?: @array
  }.to_s
end