lib/groupdocs/api/entity.rb in groupdocs-1.2.11 vs lib/groupdocs/api/entity.rb in groupdocs-1.3.0
- old
+ new
@@ -47,11 +47,11 @@
# @return [Hash]
#
def to_hash
hash = {}
instance_variables.each do |variable|
- key = variable.to_s.delete(?@).to_sym
+ key = variable.to_s.delete('@').to_sym
value = instance_variable_get(variable)
hash[key] = case value
when GroupDocs::Api::Entity
value.to_hash
@@ -67,20 +67,19 @@
hash
end
#
# Inspects object using accessors instead of instance variables values.
- #
# @api private
#
def inspect
not_nil_variables = instance_variables.select do |variable|
- !send(variable_to_accessor(variable)).nil?
+ !send(variable.to_s.underscore.delete('@')).nil?
end
variables = not_nil_variables.map do |variable|
- accessor = variable_to_accessor(variable)
+ accessor = variable.to_s.underscore.delete('@').to_sym
value = send(accessor)
value = case value
when Symbol then ":#{value}"
when String then "\"#{value}\""
else value
@@ -99,45 +98,14 @@
end
private
#
- # Converts instance variable symbol to accessor method symbol.
- # @api private
- #
- def variable_to_accessor(variable)
- word = variable.to_s.delete(?@)
- word.gsub!(/(?<=[a-z])[A-Z]/) { |match| "_#{match}" }
- word.downcase!
- word.to_sym
- end
-
- #
- # Converts accessor symbol to instance variable symbol.
- # @api private
- #
- def accessor_to_variable(accessor)
- word = accessor.to_s
- word.capitalize!
- word.gsub!(/_([a-z])/) { |match| match.upcase }
- word.gsub!(/_/, '')
- "@#{word}".to_sym
- end
-
- #
# Returns class name.
# @api private
#
def class_name
- self.class.name.split('::').last.downcase
- end
-
- #
- # Returns pluralized class name.
- # @api private
- #
- def pluralized_class_name
- "#{class_name}s"
+ self.class.name.demodulize.downcase
end
end # Entity
end # Api
end # GroupDocs