Class: FilterSettings
- Inherits:
-
Object
- Object
- FilterSettings
- Defined in:
- lib/helpers/filter_settings.rb
Overview
Holds a collection of filter settings. Filter settings are normally set via the command line as flag options.
Instance Method Summary collapse
- #get_from_args(flag) ⇒ String, Nil
- #has_general_search_term ⇒ Object
- #has_group_filter_term ⇒ Object
- #has_group_search_for ⇒ Object
- #has_test_filter_term ⇒ Object
- #has_test_runner_filter_term ⇒ Object
- #has_test_runner_search_for ⇒ Object
- #has_test_search_for ⇒ Object
-
#initialize(general_search_term: nil, test_filter_term: nil, test_search_for: nil, group_filter_term: nil, group_search_for: nil, test_runner_filter_term: nil, test_runner_search_for: nil) ⇒ FilterSettings
constructor
A new instance of FilterSettings.
- #is_not_empty ⇒ Object
- #to_properties ⇒ Object
Constructor Details
#initialize(general_search_term: nil, test_filter_term: nil, test_search_for: nil, group_filter_term: nil, group_search_for: nil, test_runner_filter_term: nil, test_runner_search_for: nil) ⇒ FilterSettings
Returns a new instance of FilterSettings.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/helpers/filter_settings.rb', line 6 def initialize( general_search_term: nil, test_filter_term: nil, test_search_for: nil, group_filter_term: nil, group_search_for: nil, test_runner_filter_term: nil, test_runner_search_for: nil ) @general_search_term = general_search_term || get_from_args(FilterProps::GENERAL_SEARCH_TERM) @test_filter_term = test_filter_term || get_from_args(FilterProps::TEST_FILTER_TERM) @test_search_for = test_search_for || get_from_args(FilterProps::TEST_SEARCH_FOR) @group_filter_term = group_filter_term || get_from_args(FilterProps::GROUP_FILTER_TERM) @group_search_for = group_search_for || get_from_args(FilterProps::GROUP_SEARCH_FOR) @test_runner_filter_term = test_runner_filter_term || get_from_args(FilterProps::TEST_RUNNER_FILTER_TERM) @test_runner_search_for = test_runner_search_for || get_from_args(FilterProps::TEST_RUNNER_SEARCH_FOR) end |
Instance Method Details
#get_from_args(flag) ⇒ String, Nil
78 79 80 81 82 83 |
# File 'lib/helpers/filter_settings.rb', line 78 def get_from_args(flag) index = ARGV.find_index(flag) return ARGV[index + 1] if index && index != ARGV.length - 1 nil end |
#has_general_search_term ⇒ Object
24 25 26 |
# File 'lib/helpers/filter_settings.rb', line 24 def has_general_search_term !@general_search_term.nil? && @general_search_term.length.positive? end |
#has_group_filter_term ⇒ Object
36 37 38 |
# File 'lib/helpers/filter_settings.rb', line 36 def has_group_filter_term !@group_filter_term.nil? && @group_filter_term.length.positive? end |
#has_group_search_for ⇒ Object
40 41 42 |
# File 'lib/helpers/filter_settings.rb', line 40 def has_group_search_for !@group_search_for.nil? && @group_search_for.length.positive? end |
#has_test_filter_term ⇒ Object
28 29 30 |
# File 'lib/helpers/filter_settings.rb', line 28 def has_test_filter_term !@test_filter_term.nil? && @test_filter_term.length.positive? end |
#has_test_runner_filter_term ⇒ Object
44 45 46 |
# File 'lib/helpers/filter_settings.rb', line 44 def has_test_runner_filter_term !@test_runner_filter_term.nil? && @test_runner_filter_term.length.positive? end |
#has_test_runner_search_for ⇒ Object
48 49 50 |
# File 'lib/helpers/filter_settings.rb', line 48 def has_test_runner_search_for !@test_runner_search_for.nil? && @test_runner_search_for.length.positive? end |
#has_test_search_for ⇒ Object
32 33 34 |
# File 'lib/helpers/filter_settings.rb', line 32 def has_test_search_for !@test_search_for.nil? && @test_search_for.length.positive? end |
#is_not_empty ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/helpers/filter_settings.rb', line 52 def is_not_empty hasGeneralSearchTerm || hasTestFilterTerm || hasTestSearchFor || hasGroupFilterTerm || hasGroupSearchFor || hasTestRunnerFilterTerm || hasTestRunnerSearchFor end |
#to_properties ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/helpers/filter_settings.rb', line 62 def to_properties props = [] props << [FilterProps::GENERAL_SEARCH_TERM, @general_search_term] if has_general_search_term props << [FilterProps::TEST_FILTER_TERM, @test_filter_term] if has_test_filter_term props << [FilterProps::TEST_SEARCH_FOR, @test_search_for] if has_test_search_for props << [FilterProps::GROUP_FILTER_TERM, @group_filter_term] if has_group_filter_term props << [FilterProps::GROUP_SEARCH_FOR, @group_search_for] if has_group_search_for props << [FilterProps::TEST_RUNNER_FILTER_TERM, @test_runner_filter_term] if has_test_runner_filter_term props << [FilterProps::TEST_RUNNER_SEARCH_FOR, @test_runner_search_for] if has_test_runner_search_for props end |