Class: Rufio::FilterManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rufio/filter_manager.rb

Overview

Manages filtering of directory entries

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFilterManager

Returns a new instance of FilterManager.



8
9
10
11
12
13
# File 'lib/rufio/filter_manager.rb', line 8

def initialize
  @filter_mode = false
  @filter_query = ''
  @original_entries = []
  @filtered_entries = []
end

Instance Attribute Details

#filter_modeObject (readonly)

Returns the value of attribute filter_mode.



6
7
8
# File 'lib/rufio/filter_manager.rb', line 6

def filter_mode
  @filter_mode
end

#filter_queryObject (readonly)

Returns the value of attribute filter_query.



6
7
8
# File 'lib/rufio/filter_manager.rb', line 6

def filter_query
  @filter_query
end

Instance Method Details

#apply_filterArray<Hash>

Apply filter to entries

Returns:

  • (Array<Hash>)

    Filtered entries



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rufio/filter_manager.rb', line 61

def apply_filter
  if @filter_query.empty?
    @filtered_entries = @original_entries.dup
  else
    query_downcase = @filter_query.downcase
    @filtered_entries = @original_entries.select do |entry|
      entry[:name].downcase.include?(query_downcase)
    end
  end
  @filtered_entries
end

#clear_filterObject

Clear filter mode



74
75
76
77
78
79
# File 'lib/rufio/filter_manager.rb', line 74

def clear_filter
  @filter_mode = false
  @filter_query = ''
  @filtered_entries = []
  @original_entries = []
end

#exit_filter_mode_keep_filterObject

Exit filter mode while keeping the filter



82
83
84
85
# File 'lib/rufio/filter_manager.rb', line 82

def exit_filter_mode_keep_filter
  @filter_mode = false
  # Keep @filter_query and @filtered_entries
end

#filter_active?Boolean

Check if filter is active

Returns:

  • (Boolean)


89
90
91
# File 'lib/rufio/filter_manager.rb', line 89

def filter_active?
  @filter_mode || !@filter_query.empty?
end

#filtered_entriesArray<Hash>

Get filtered entries

Returns:

  • (Array<Hash>)


95
96
97
# File 'lib/rufio/filter_manager.rb', line 95

def filtered_entries
  @filtered_entries
end

#handle_filter_input(key) ⇒ Symbol

Handle filter input character

Parameters:

  • key (String)

    Input key

Returns:

  • (Symbol)

    :exit_clear, :exit_keep, :continue, or :backspace_exit



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rufio/filter_manager.rb', line 28

def handle_filter_input(key)
  case key
  when "\e" # ESC - clear filter and exit
    :exit_clear
  when "\r", "\n" # Enter - keep filter and exit
    :exit_keep
  when "\u007f", "\b" # Backspace
    if @filter_query.length > 0
      @filter_query = @filter_query[0...-1]
      apply_filter
      :continue
    else
      :backspace_exit
    end
  else
    # Printable characters (alphanumeric, symbols, Japanese, etc.)
    if key.length == 1 && key.ord >= 32 && key.ord < 127 # ASCII printable
      @filter_query += key
      apply_filter
      :continue
    elsif key.bytesize > 1 # Multi-byte characters (Japanese, etc.)
      @filter_query += key
      apply_filter
      :continue
    else
      # Ignore other keys (Ctrl+c, etc.)
      :continue
    end
  end
end

#restart_filter_mode(entries) ⇒ Object

Restart filter mode with existing query

Parameters:

  • entries (Array<Hash>)

    Directory entries



108
109
110
111
112
# File 'lib/rufio/filter_manager.rb', line 108

def restart_filter_mode(entries)
  @filter_mode = true
  @original_entries = entries.dup if @original_entries.empty?
  apply_filter
end

#start_filter_mode(entries) ⇒ Object

Start filter mode with the given entries

Parameters:

  • entries (Array<Hash>)

    Directory entries to filter



17
18
19
20
21
22
23
# File 'lib/rufio/filter_manager.rb', line 17

def start_filter_mode(entries)
  @filter_mode = true
  @filter_query = ''
  @original_entries = entries.dup
  @filtered_entries = @original_entries.dup
  true
end

#update_entries(entries) ⇒ Object

Update original entries (e.g., after directory refresh)

Parameters:

  • entries (Array<Hash>)

    New entries



101
102
103
104
# File 'lib/rufio/filter_manager.rb', line 101

def update_entries(entries)
  @original_entries = entries.dup
  apply_filter if filter_active?
end