Class: Jaspion::Kilza::Property
- Inherits:
-
Object
- Object
- Jaspion::Kilza::Property
- Defined in:
- lib/jaspion/kilza/property.rb
Overview
Represents a single Class property
Direct Known Subclasses
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.
Class Method Summary collapse
-
.clean(str) ⇒ String
Removes everything except numbers and letters.
-
.normalize(str) ⇒ String
Cleans the string and make it lowercase.
Instance Method Summary collapse
- #==(pr) ⇒ Object
- #boolean? ⇒ Boolean
-
#class_name ⇒ Object
If this Property represents a new Class, it returns the formatted class name.
- #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.
29 30 31 32 33 34 35 36 |
# 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 |
Instance Attribute Details
#array ⇒ Object Also known as: array?
Indicates if the property represents an array of objects
21 22 23 |
# File 'lib/jaspion/kilza/property.rb', line 21 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
26 27 28 |
# File 'lib/jaspion/kilza/property.rb', line 26 def key @key end |
#name ⇒ Object
Normalized property name Starts with _ or alphanumeric character and doesn’t contain any special character
8 9 10 |
# File 'lib/jaspion/kilza/property.rb', line 8 def name @name end |
#original_name ⇒ Object
Original JSON property name
11 12 13 |
# File 'lib/jaspion/kilza/property.rb', line 11 def original_name @original_name end |
#original_type ⇒ Object
Ruby string type Can be object, fixnum, float, falseclass, trueclass and nilclass
15 16 17 |
# File 'lib/jaspion/kilza/property.rb', line 15 def original_type @original_type end |
#type ⇒ Object
Property type name
18 19 20 |
# File 'lib/jaspion/kilza/property.rb', line 18 def type @type end |
Class Method Details
.clean(str) ⇒ String
Removes everything except numbers and letters.
82 83 84 85 |
# File 'lib/jaspion/kilza/property.rb', line 82 def self.clean(str) return if str.nil? str.gsub(/[^a-zA-Z0-9]/, '') end |
.normalize(str) ⇒ String
Cleans the string and make it lowercase.
92 93 94 95 96 97 98 |
# 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 |
Instance Method Details
#==(pr) ⇒ Object
58 59 60 |
# File 'lib/jaspion/kilza/property.rb', line 58 def ==(pr) @name == pr.name end |
#boolean? ⇒ Boolean
46 47 48 |
# File 'lib/jaspion/kilza/property.rb', line 46 def boolean? @original_type == 'trueclass' || @original_type == 'falseclass' end |
#class_name ⇒ Object
If this Property represents a new Class, it returns the formatted class name
64 65 66 |
# File 'lib/jaspion/kilza/property.rb', line 64 def class_name Jaspion::Kilza::Class.normalize(@original_name) end |
#fixnum? ⇒ Boolean
42 43 44 |
# File 'lib/jaspion/kilza/property.rb', line 42 def fixnum? @original_type == 'fixnum' end |
#float? ⇒ Boolean
50 51 52 |
# File 'lib/jaspion/kilza/property.rb', line 50 def float? @original_type == 'float' end |
#null? ⇒ Boolean
54 55 56 |
# File 'lib/jaspion/kilza/property.rb', line 54 def null? @original_type == 'nilclass' end |
#object? ⇒ Boolean
38 39 40 |
# File 'lib/jaspion/kilza/property.rb', line 38 def object? @original_type == 'hash' end |
#to_s ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/jaspion/kilza/property.rb', line 68 def to_s { name: @name, original_name: @original_name, type: @type, array?: @array }.to_s end |