class OTRS::Relation

Public Instance Methods

limit(int) click to toggle source
# File lib/otrs_connector/otrs/relation.rb, line 48
def limit(int)
  self[0...int]
end
order(field='id',order='desc') click to toggle source

This is hit and miss for some reason… sometimes the order works correctly, sometimes it’s backwards (desc/asc)

# File lib/otrs_connector/otrs/relation.rb, line 53
def order(field='id',order='desc')
  case order.downcase.to_s
  when 'asc'
    self.sort { |a,b| b.send(field.to_s) <=> a.send(field.to_s) }
  when 'desc'                                               
    self.sort { |a,b| a.send(field.to_s) <=> b.send(field.to_s) }
  end
end
uniqify() click to toggle source

Removes duplicate records

# File lib/otrs_connector/otrs/relation.rb, line 63
def uniqify
  ids = []
  results = self.class.new
  self.each do |s|
    results << s unless ids.include? s.id
    ids << s.id
  end
  results
end
where(attributes) click to toggle source

Allows chaining where methods, this method only parses the already returned objects from OTRS, currently. In the future I hope to have this grouping the where chains together into one OTRS request for all in the chain

# File lib/otrs_connector/otrs/relation.rb, line 34
def where(attributes)
  relation = self.class.new
  attributes.each do |lookup_key,lookup_value|
    self.each do |object|
      object.attributes.each do |object_key,object_value|
        if object_key == lookup_key and object_value == lookup_value
          relation << object
        end
      end
    end
  end
  return relation
end