Sha256: e30bf2565f5366e1cccb731966a6905db68c83e1911ac70375503c71d4ed7279

Contents?: true

Size: 765 Bytes

Versions: 2

Compression:

Stored size: 765 Bytes

Contents

# encoding: utf-8

module Selector

  # The condition checks if the function returns truthy result for a value
  #
  # @example (see #[])
  #
  class Function < Condition

    # @!method initialize(function)
    # Initializes the condition with a function
    #
    # @param [#call] function
    #
    def initialize(_)
      super
    end

    # Checks if the function returns truthy for value
    #
    # @example
    #   condition = Selector::Function.new -> v { v[/foo/] }
    #   condition[:foo] # => true
    #   condition[:bar] # => false
    #
    # @param (see Selector::Condition#[])
    #
    # @return (see Selector::Condition#[])
    #
    def [](value)
      attribute.call(value) ? true : false
    end

  end # class Function

end # module Selector

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
selector-0.0.3 lib/selector/function.rb
selector-0.0.2 lib/selector/function.rb