Class: FuzzySelector
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#previewcmd ⇒ Object
readonly
Returns the value of attribute previewcmd.
Instance Method Summary collapse
-
#initialize(items, previewcmd = nil) ⇒ FuzzySelector
constructor
A new instance of FuzzySelector.
- #select(&blk) ⇒ Object
- #select_by(&blk) ⇒ Object
Constructor Details
#initialize(items, previewcmd = nil) ⇒ FuzzySelector
Returns a new instance of FuzzySelector.
3 4 5 6 |
# File 'lib/fuzzy_selector.rb', line 3 def initialize(items, previewcmd=nil) @items = items @previewcmd = previewcmd end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
2 3 4 |
# File 'lib/fuzzy_selector.rb', line 2 def items @items end |
#previewcmd ⇒ Object (readonly)
Returns the value of attribute previewcmd.
2 3 4 |
# File 'lib/fuzzy_selector.rb', line 2 def previewcmd @previewcmd end |
Instance Method Details
#select(&blk) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/fuzzy_selector.rb', line 8 def select(&blk) IO.popen(selectorcmd, "r+") do |pipe| items.each { pipe.puts blk.call(_1) } pipe.close_write pipe.readlines(chomp: true) end end |
#select_by(&blk) ⇒ Object
16 17 18 19 |
# File 'lib/fuzzy_selector.rb', line 16 def select_by(&blk) identifiers = select(&blk) items.select { identifiers.include?(blk.call(_1)) } end |