Class: Kilza::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/kilza/property.rb

Overview

Represents a single Class property

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, array, key) ⇒ Property

Returns a new instance of Property.



28
29
30
31
32
33
34
35
# File 'lib/kilza/property.rb', line 28

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

Instance Attribute Details

#arrayObject Also known as: array?

Indicates if the property represents an array of objects



20
21
22
# File 'lib/kilza/property.rb', line 20

def array
  @array
end

#keyObject Also known as: key?

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



25
26
27
# File 'lib/kilza/property.rb', line 25

def key
  @key
end

#nameObject

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



7
8
9
# File 'lib/kilza/property.rb', line 7

def name
  @name
end

#original_nameObject

Original JSON property name



10
11
12
# File 'lib/kilza/property.rb', line 10

def original_name
  @original_name
end

#original_typeObject

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



14
15
16
# File 'lib/kilza/property.rb', line 14

def original_type
  @original_type
end

#typeObject

Property type name



17
18
19
# File 'lib/kilza/property.rb', line 17

def type
  @type
end

Instance Method Details

#==(pr) ⇒ Object



57
58
59
# File 'lib/kilza/property.rb', line 57

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

#boolean?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/kilza/property.rb', line 45

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

#fixnum?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/kilza/property.rb', line 41

def fixnum?
  @original_type == 'fixnum'
end

#float?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/kilza/property.rb', line 49

def float?
  @original_type == 'float'
end

#null?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/kilza/property.rb', line 53

def null?
  @original_type == 'nilclass'
end

#object?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/kilza/property.rb', line 37

def object?
  @original_type == 'hash'
end

#to_sObject



61
62
63
64
65
66
67
68
# File 'lib/kilza/property.rb', line 61

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