Class: Masklen::BatchResult

Inherits:
Struct
  • Object
show all
Defined in:
lib/masklen/types.rb

Overview

The result of a batch IP lookup. Each entry in results is either a LookupResult or a BatchItemError.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#resultsObject

Returns the value of attribute results

Returns:

  • (Object)

    the current value of results



140
141
142
# File 'lib/masklen/types.rb', line 140

def results
  @results
end

Class Method Details

.from_hash(hash) ⇒ Object

Build a BatchResult from a parsed JSON hash. Each element in the “results” array is mapped to a LookupResult when it has an “ip” key and no “error_code”, or to a BatchItemError otherwise.



147
148
149
150
151
152
153
154
155
156
# File 'lib/masklen/types.rb', line 147

def self.from_hash(hash)
  items = (hash["results"] || []).map do |item|
    if item.key?("error_code")
      BatchItemError.from_hash(item)
    else
      LookupResult.from_hash(item)
    end
  end
  new(results: items)
end