lib/jaspion/kilza/property.rb in jaspion-kilza-1.1.1 vs lib/jaspion/kilza/property.rb in jaspion-kilza-1.1.2
- old
+ new
@@ -24,12 +24,12 @@
# 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)
+ def initialize(name, type, array, key = '')
+ @name = Jaspion::Kilza::Property.normalize(name)
@original_name = name
@type = type
@array = array
@key = key
@original_type = type
@@ -57,16 +57,45 @@
def ==(pr)
@name == pr.name
end
+ # If this Property represents a new Class,
+ # it returns the formatted class name
+ def class_name
+ Jaspion::Kilza::Class.normalize(@original_name)
+ end
+
def to_s
{
name: @name,
original_name: @original_name,
type: @type,
array?: @array
}.to_s
+ end
+
+ # Removes everything except numbers and letters.
+ #
+ # @param str [String] string to be cleaned
+ #
+ # @return [String] cleaned string
+ def self.clean(str)
+ return if str.nil?
+ str.gsub(/[^a-zA-Z0-9]/, '')
+ end
+
+ # Cleans the string and make it lowercase.
+ #
+ # @param str [String] string to be cleaned
+ #
+ # @return [String] cleaned string
+ 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
end
end
end