lib/red_amber/subframes.rb in red_amber-0.4.2 vs lib/red_amber/subframes.rb in red_amber-0.5.0

- old
+ new

@@ -18,25 +18,32 @@ @selectors = selectors @size = selectors.size @sizes = [] end + # Generic iterator method def each @selectors.each end end # Boolean selectors of sub-dataframes class Filters < Selectors + # Return sizes of filter + # @return [Array<Integer>] + # sizes of each sub dataframes. + # Counts true for each filter. def sizes - # count true @sizes = @selectors.map { |s| s.to_a.count { _1 } } # rubocop:disable Performance/Size end end # Index selectors of sub-dataframes class Indices < Selectors + # Return sizes of selector indices. + # @return [Array<Integer>] + # sizes of each sub dataframes. def sizes @sizes = @selectors.map(&:size) end end @@ -91,11 +98,11 @@ # 0 6 C false # # @since 0.4.0 # def by_group(group) - SubFrames.new(group.dataframe, group.filters) + SubFrames.by_filters(group.dataframe, group.filters) end # Create a new SubFrames object from a DataFrame and an array of indices. # # @api private @@ -289,18 +296,18 @@ end selectors = yield(dataframe) end - if dataframe.empty? || selectors.nil? || selectors.empty? + if dataframe.empty? || selectors.nil? || selectors.size.zero? # rubocop:disable Style/ZeroLengthPredicate @baseframe = DataFrame.new @selectors = Selectors.new([]) else @baseframe = dataframe @selectors = - if selectors[0].boolean? + if selectors.first.boolean? Filters.new(selectors) - elsif selectors[0].numeric? + elsif selectors.first.numeric? Indices.new(selectors) else raise SubFramesArgumentError, "illegal type: #{selectors}" end end