Class: Glark::MatchOptions
- Includes:
- OptionUtil
- Defined in:
- lib/glark/match/options.rb
Constant Summary
Constants included from OptionUtil
Instance Attribute Summary
Attributes inherited from MatchSpec
#expr, #extended, #extract_matches, #ignorecase, #whole_lines, #whole_words
Instance Method Summary collapse
- #add_as_options(optdata) ⇒ Object
- #config_fields ⇒ Object
- #dump_fields ⇒ Object
-
#initialize(colors, optdata) ⇒ MatchOptions
constructor
A new instance of MatchOptions.
- #update_fields(fields) ⇒ Object
Methods included from OptionUtil
#add_opt, #add_opt_arg, #add_opt_blk, #add_opt_false, #add_opt_int, #add_opt_str, #add_opt_true, #colorize, #set, #set_var, #to_boolean
Methods inherited from MatchSpec
#create_expression_factory, #read_expression, #set_text_color, #set_text_colors, #text_colors
Constructor Details
#initialize(colors, optdata) ⇒ MatchOptions
Returns a new instance of MatchOptions.
15 16 17 18 |
# File 'lib/glark/match/options.rb', line 15 def initialize colors, optdata super colors optdata end |
Instance Method Details
#add_as_options(optdata) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/glark/match/options.rb', line 47 def optdata add_opt_true optdata, :whole_words, %w{ -w --word } add_opt_true optdata, :ignorecase, %w{ -i --ignore-case } add_opt_true optdata, :whole_lines, %w{ -x --line-regexp } add_opt_true optdata, :extended, %w{ --extended } optdata << { :tags => %w{ -f --file }, :arg => [ :string ], :set => Proc.new { |fname| @expr = create_expression_factory.read_file fname } } add_opt_blk(optdata, %w{ -o -a }) do |md, opt, args| args.unshift opt @expr = create_expression_factory.make_expression args end optdata << { :tags => %w{ --text-color }, :arg => [ :string ], :set => Proc.new { |val| @colors.text_colors = [ @colors.create_color("text-color", val) ] } } add_opt_true optdata, :extract_matches, %w{ -y --extract-matches } end |
#config_fields ⇒ Object
20 21 22 23 24 25 |
# File 'lib/glark/match/options.rb', line 20 def config_fields { "ignore-case" => @ignorecase, "text-color" => text_colors.join(' '), } end |
#dump_fields ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/glark/match/options.rb', line 27 def dump_fields { "expr" => @expr, "extract_matches" => @extract_matches, "ignorecase" => @ignorecase, "text_colors" => text_colors.compact.collect { |hl| colorize(hl, "text") }.join(", "), "whole_lines" => @whole_lines, "whole_words" => @whole_words, } end |
#update_fields(fields) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/glark/match/options.rb', line 38 def update_fields fields fields.each do |name, values| case name when "ignore-case" @ignorecase = to_boolean values.last end end end |