Class: Options::PartialOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/filterameter/options/partial_options.rb

Overview

Partial Options

Class PartialOptions parses the options passed in as partial, then exposes those. Here are the options along with their valid values:

  • match: anywhere (default), from_start, dynamic

  • case_sensitive: true, false (default)

Options may be specified by passing a hash with the option keys:

partial: { match: :from_start, case_sensitive: true }

There are two shortcuts: the partial option can be declared with ‘true`, which just uses the defaults; or the partial option can be declared with the match option directly, such as partial: :from_start.

Constant Summary collapse

VALID_OPTIONS =
%i[match case_sensitive].freeze
VALID_MATCH_OPTIONS =
%w[anywhere from_start dynamic].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ PartialOptions

Returns a new instance of PartialOptions.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/filterameter/options/partial_options.rb', line 21

def initialize(options)
  @match = 'anywhere'
  @case_sensitive = false

  if options.is_a?(TrueClass)
    nil
  elsif options.is_a? Hash
    evaluate_hash(options)
  elsif options.is_a?(String) || options.is_a?(Symbol)
    assign_match(options)
  end
end

Instance Method Details

#case_sensitive?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/filterameter/options/partial_options.rb', line 34

def case_sensitive?
  @case_sensitive
end

#match_anywhere?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/filterameter/options/partial_options.rb', line 38

def match_anywhere?
  @match == 'anywhere'
end

#match_dynamically?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/filterameter/options/partial_options.rb', line 46

def match_dynamically?
  @match == 'dynamic'
end

#match_from_start?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/filterameter/options/partial_options.rb', line 42

def match_from_start?
  @match == 'from_start'
end