Class: Glark::OutputSpec
- Inherits:
-
Object
- Object
- Glark::OutputSpec
- Defined in:
- lib/glark/output/spec.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#colors ⇒ Object
readonly
Returns the value of attribute colors.
-
#context ⇒ Object
lines before and after.
-
#count ⇒ Object
only count the matches.
-
#file_names_only ⇒ Object
display only the file names.
-
#filter ⇒ Object
display only matches.
-
#invert_match ⇒ Object
display non-matching lines.
-
#label ⇒ Object
Returns the value of attribute label.
-
#match_limit ⇒ Object
the maximum number of matches to display per file.
-
#out ⇒ Object
Returns the value of attribute out.
-
#show_file_names ⇒ Object
display file names.
-
#show_line_numbers ⇒ Object
display numbers of matching lines.
-
#style ⇒ Object
grep, glark.
-
#write_null ⇒ Object
in @file_names_only mode, write ‘0’ instead of ‘n’.
Instance Method Summary collapse
- #create_output_type(file) ⇒ Object
- #file_highlight ⇒ Object
- #highlight ⇒ Object
-
#initialize(colors) ⇒ OutputSpec
constructor
A new instance of OutputSpec.
- #line_number_highlight ⇒ Object
- #output_type_cls ⇒ Object
- #set_file_names_only(invert_match) ⇒ Object
Constructor Details
#initialize(colors) ⇒ OutputSpec
Returns a new instance of OutputSpec.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/glark/output/spec.rb', line 31 def initialize colors @colors = colors @context = Glark::Context.new @count = false @file_names_only = false @filter = true @highlight = nil @invert_match = false @label = nil @match_limit = nil @out = $stdout @show_file_names = nil # nil == > 1; true == >= 1; false means never @show_line_numbers = true @style = nil @write_null = false @output_cls = nil self.style = "glark" end |
Instance Attribute Details
#colors ⇒ Object (readonly)
Returns the value of attribute colors.
28 29 30 |
# File 'lib/glark/output/spec.rb', line 28 def colors @colors end |
#context ⇒ Object
lines before and after
16 17 18 |
# File 'lib/glark/output/spec.rb', line 16 def context @context end |
#count ⇒ Object
only count the matches
17 18 19 |
# File 'lib/glark/output/spec.rb', line 17 def count @count end |
#file_names_only ⇒ Object
display only the file names
18 19 20 |
# File 'lib/glark/output/spec.rb', line 18 def file_names_only @file_names_only end |
#filter ⇒ Object
display only matches
19 20 21 |
# File 'lib/glark/output/spec.rb', line 19 def filter @filter end |
#invert_match ⇒ Object
display non-matching lines
20 21 22 |
# File 'lib/glark/output/spec.rb', line 20 def invert_match @invert_match end |
#label ⇒ Object
Returns the value of attribute label.
21 22 23 |
# File 'lib/glark/output/spec.rb', line 21 def label @label end |
#match_limit ⇒ Object
the maximum number of matches to display per file
22 23 24 |
# File 'lib/glark/output/spec.rb', line 22 def match_limit @match_limit end |
#out ⇒ Object
Returns the value of attribute out.
23 24 25 |
# File 'lib/glark/output/spec.rb', line 23 def out @out end |
#show_file_names ⇒ Object
display file names
24 25 26 |
# File 'lib/glark/output/spec.rb', line 24 def show_file_names @show_file_names end |
#show_line_numbers ⇒ Object
display numbers of matching lines
25 26 27 |
# File 'lib/glark/output/spec.rb', line 25 def show_line_numbers @show_line_numbers end |
#style ⇒ Object
grep, glark
29 30 31 |
# File 'lib/glark/output/spec.rb', line 29 def style @style end |
#write_null ⇒ Object
in @file_names_only mode, write ‘0’ instead of ‘n’
26 27 28 |
# File 'lib/glark/output/spec.rb', line 26 def write_null @write_null end |
Instance Method Details
#create_output_type(file) ⇒ Object
78 79 80 |
# File 'lib/glark/output/spec.rb', line 78 def create_output_type file output_type_cls.new file, self end |
#file_highlight ⇒ Object
56 57 58 |
# File 'lib/glark/output/spec.rb', line 56 def file_highlight @colors.file_name_color end |
#highlight ⇒ Object
60 61 62 |
# File 'lib/glark/output/spec.rb', line 60 def highlight @colors.text_color_style end |
#line_number_highlight ⇒ Object
52 53 54 |
# File 'lib/glark/output/spec.rb', line 52 def line_number_highlight @colors.line_number_color end |
#output_type_cls ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/glark/output/spec.rb', line 82 def output_type_cls @output_cls ||= if @count if @style == "grep" Grep::Count else Glark::Count end elsif @file_names_only FileNameOnly elsif !@filter UnfilteredLines elsif @style == "grep" Grep::Lines else Glark::Lines end end |
#set_file_names_only(invert_match) ⇒ Object
100 101 102 103 |
# File 'lib/glark/output/spec.rb', line 100 def set_file_names_only invert_match @file_names_only = true @invert_match = invert_match end |