lib/red_amber/helper.rb in red_amber-0.3.0 vs lib/red_amber/helper.rb in red_amber-0.4.0

- old
+ new

@@ -1,30 +1,35 @@ # frozen_string_literal: true module RedAmber - # mix-in for the class DataFrame + # Mix-in for the class DataFrame module Helper private # If num is larger than 1 return 's' to be plural. # - # @param num [Numeric] some number. - # @return ['s', ''] return 's' if num is larger than 1. + # @param num [Numeric] + # some number. + # @return ['s', ''] + # return 's' if num is larger than 1. # Otherwise return ''. + # def pl(num) num > 1 ? 's' : '' end - # Parse the argments in an Array - # and returns a parsed Array. + # Parse the argments in an Array and returns a parsed Array. # # @param args # [<Integer, Symbol, true, false, nil, Array, Range, Enumerator, String, Float>] # arguments. - # @param array_size [Integer] size of target Array to use in a endless Range. - # @return [<Integer, Symbol, true, false, nil>] parsed flat Array. + # @param array_size [Integer] + # size of target Array to use in a endless Range. + # @return [<Integer, Symbol, true, false, nil>] + # parsed flat Array. # @note This method is recursively called to parse. + # def parse_args(args, array_size) args.flat_map do |elem| case elem when Integer, Symbol, NilClass, TrueClass, FalseClass elem @@ -44,13 +49,17 @@ end end # Parse a Range to an Array # - # @param range [Range] Range to parse. - # @param array_size [Integer] size of target Array to use in a endless Range. - # @return [Array<Integer, Symbol, String>] parsed Array. + # @param range [Range] + # range to parse. + # @param array_size [Integer] + # size of target Array to use in a endless Range. + # @return [Array<Integer, Symbol, String>] + # parsed Array. + # def parse_range(range, array_size) bg = range.begin en = range.end if [bg, en].any?(Integer) bg += array_size if bg&.negative? @@ -68,6 +77,57 @@ else Array(range) end end end + + # rubocop:disable Layout/LineLength + + # Helper for Arrow Functions + module ArrowFunction + module_function + + # Find Arrow's compute function. + # + # {https://arrow.apache.org/docs/cpp/compute.html} + # @param function_name [Symbol] + # function name. + # @return [Arrow::Function] + # arrow compute function object. + # @example + # RedAmber::ArrowFunction.find(:array_sort_indices) + # + # # => + # #<Arrow::Function:0x7fa8838a0d80 ptr=0x7fa87e9b7320 array_sort_indices(array, {order=Ascending, null_placement=AtEnd}): Return the indices that would sort an array> + # + def find(function_name) + Arrow::Function.find(function_name) + end + + # Show document of Arrow's compute function. + # + # @param function_name [Symbol] + # function name. + # @return [String] + # document of compute function object. + # @example + # puts RedAmber::ArrowFunction.arrow_doc(:array_sort_indices) + # + # # => + # array_sort_indices(array, {order=Ascending, null_placement=AtEnd}): Return the indices that would sort an array + # ------------------ + # This function computes an array of indices that define a stable sort + # of the input array. By default, Null values are considered greater + # than any other value and are therefore sorted at the end of the array. + # For floating-point types, NaNs are considered greater than any + # other non-null value, but smaller than null values. + # + # The handling of nulls and NaNs can be changed in ArraySortOptions. + # + def arrow_doc(function_name) + f = find(function_name) + "#{f}\n#{'-' * function_name.size}\n#{f.doc.description}" + end + end + + # rubocop:enable Layout/LineLength end