Sha256: 0c4a8a30199e9eceac2613a4476410505f7dc759bcbdf717d168034bedca684f

Contents?: true

Size: 729 Bytes

Versions: 1

Compression:

Stored size: 729 Bytes

Contents

# encoding: utf-8

module Selector

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

    # 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

1 entries across 1 versions & 1 rubygems

Version Path
selector-0.0.1 lib/selector/function.rb