class String

Public Instance Methods

to_operation()
Alias for: to_operations
to_operations() click to toggle source
# File lib/operations/core_ext.rb, line 2
def to_operations
  real_size = self.blank? ? 0 : self.strip.size
  return [] if real_size == 0

  by_uuid = Operations.from_uuid(self)
  return by_uuid unless by_uuid.nil?

  operations_list = []

  begin
    json_operations = JSON.parse(self)
  rescue JSON::ParserError
    raise Operations::Errors::InvalidOperationError.new('Could not parsel this String into a Operations::Operation object')
  end
  if json_operations.class == Array
    json_operations.each do |json_value|
      operations_list.append(json_value.to_s.to_operations)
    end
  elsif json_operations.class == Hash # OK
    json_operations.deep_symbolize_keys!
    operations_list = Operations::Operation.new(**json_operations)
  end

  operations_list
end
Also aliased as: to_operation