Class: Filterameter::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.



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

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

  case options
  when TrueClass
    nil
  when Hash
    evaluate_hash(options)
  when String, Symbol
    assign_match(options)
  end
end

Instance Method Details

#case_sensitive?Boolean

Returns:

  • (Boolean)


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

def case_sensitive?
  @case_sensitive
end

#match_anywhere?Boolean

Returns:

  • (Boolean)


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

def match_anywhere?
  @match == 'anywhere'
end

#match_dynamically?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/filterameter/options/partial_options.rb', line 49

def match_dynamically?
  @match == 'dynamic'
end

#match_from_start?Boolean

Returns:

  • (Boolean)


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

def match_from_start?
  @match == 'from_start'
end

#to_sObject



53
54
55
56
57
58
59
60
61
# File 'lib/filterameter/options/partial_options.rb', line 53

def to_s
  if case_sensitive?
    case_sensitive_to_s
  elsif match_anywhere?
    'true'
  else
    ":#{@match}"
  end
end