Sha256: 0e4e66d3ddb32f46dd8140b4c7ca95ee37f18c5034e2c1ea9fb53ffe7b46ba3d
Contents?: true
Size: 852 Bytes
Versions: 1
Compression:
Stored size: 852 Bytes
Contents
require 'forwardable' module Parliament class Response include Enumerable extend Forwardable attr_reader :nodes def_delegators :@nodes, :size, :each, :select, :map, :select!, :map!, :count, :length, :[] def initialize(nodes) @nodes = nodes end def filter(*types) filtered_objects = Array.new(types.size) { [] } unless types.empty? @nodes.each do |node| type_index = types.index(node.type) filtered_objects[type_index] << node unless type_index.nil? end end result = build_responses(filtered_objects) types.size == 1 ? result.first : result end def build_responses(filtered_objects) result = [] filtered_objects.each do |objects| result << Parliament::Response.new(objects) end result end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
parliament-ruby-0.2.1 | lib/parliament/response.rb |