Class: Droonga::Plugins::Groonga::Select::ResponseConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/plugins/groonga/select.rb

Instance Method Summary collapse

Instance Method Details

#convert(search_response) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/droonga/plugins/groonga/select.rb', line 68

def convert(search_response)
  select_responses = search_response.collect do |key, value|
    status_code = 0

    start_time = value["startTime"]
    start_time_in_unix_time = if start_time
                                Time.parse(start_time).to_f
                              else
                                Time.now.to_f
                              end
    elapsed_time = value["elapsedTime"] || 0
    count = value["count"]

    attributes = value["attributes"] || []
    converted_attributes = attributes.collect do |attribute|
      name = attribute["name"]
      type = attribute["type"]
      [name, type]
    end

    header = [status_code, start_time_in_unix_time, elapsed_time]
    records = value["records"]
    if records.empty?
      results = [[count], converted_attributes]
    else
      results = [[count], converted_attributes, records]
    end
    body = [results]

    [header, body]
  end
  select_responses.first
end