Class: Kilza::Property
- Inherits:
-
Object
- Object
- Kilza::Property
- Defined in:
- lib/kilza/property.rb
Overview
Represents a single Class property
Instance Attribute Summary collapse
-
#array ⇒ Object
(also: #array?)
Indicates if the property represents an array of objects.
-
#key ⇒ Object
(also: #key?)
Indicates if the property should be used for comparing purposes Used to compare if one object is equal to another one.
-
#name ⇒ Object
Normalized property name Starts with _ or alphanumeric character and doesn’t contain any special character.
-
#original_name ⇒ Object
Original JSON property name.
-
#original_type ⇒ Object
Ruby string type Can be object, fixnum, float, falseclass, trueclass and nilclass.
-
#type ⇒ Object
Property type name.
Instance Method Summary collapse
- #==(pr) ⇒ Object
- #boolean? ⇒ Boolean
- #fixnum? ⇒ Boolean
- #float? ⇒ Boolean
-
#initialize(name, type, array, key) ⇒ Property
constructor
A new instance of Property.
- #null? ⇒ Boolean
- #object? ⇒ Boolean
- #to_s ⇒ Object
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
#array ⇒ Object 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 |
#key ⇒ Object 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 |
#name ⇒ Object
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_name ⇒ Object
Original JSON property name
10 11 12 |
# File 'lib/kilza/property.rb', line 10 def original_name @original_name end |
#original_type ⇒ Object
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 |
#type ⇒ Object
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
45 46 47 |
# File 'lib/kilza/property.rb', line 45 def boolean? @original_type == 'trueclass' || @original_type == 'falseclass' end |
#fixnum? ⇒ Boolean
41 42 43 |
# File 'lib/kilza/property.rb', line 41 def fixnum? @original_type == 'fixnum' end |
#float? ⇒ Boolean
49 50 51 |
# File 'lib/kilza/property.rb', line 49 def float? @original_type == 'float' end |
#null? ⇒ Boolean
53 54 55 |
# File 'lib/kilza/property.rb', line 53 def null? @original_type == 'nilclass' end |
#object? ⇒ Boolean
37 38 39 |
# File 'lib/kilza/property.rb', line 37 def object? @original_type == 'hash' end |
#to_s ⇒ Object
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 |