class Elrec::SearchResults

Public Class Methods

new(json) click to toggle source
# File lib/elrec/search-results.rb, line 14
def initialize(json)
  @items = Array.new
  self.parse(json)
end

Public Instance Methods

check?(obj) click to toggle source
# File lib/elrec/search-results.rb, line 31
def check?(obj)
  res = false
  if(obj.size == 0)
    res = true
  else
    if(obj.instance_of?(Array))
       if(obj[0].has_key?('itemId'))
         if(obj[0].has_key?('score'))
           res = true
         end
       end
    end
  end
  return res
end
get_items() click to toggle source
# File lib/elrec/search-results.rb, line 47
def get_items
  if(@status)
    return @items
  else
    return nil
  end
end
parse(json) click to toggle source
# File lib/elrec/search-results.rb, line 19
def parse(json)
  obj = JSON.parse(json)
  if(self.check?(obj))
    obj.each do |e|
      @items.push(ItemScore.new(e["itemId"], e["score"]))
    end
    @status = true
  else
    @status = false
  end
end