Class: Glark::OutputSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/glark/output/spec.rb

Direct Known Subclasses

OutputOptions

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#colorsObject (readonly)

Returns the value of attribute colors.



28
29
30
# File 'lib/glark/output/spec.rb', line 28

def colors
  @colors
end

#contextObject

lines before and after



16
17
18
# File 'lib/glark/output/spec.rb', line 16

def context
  @context
end

#countObject

only count the matches



17
18
19
# File 'lib/glark/output/spec.rb', line 17

def count
  @count
end

#file_names_onlyObject

display only the file names



18
19
20
# File 'lib/glark/output/spec.rb', line 18

def file_names_only
  @file_names_only
end

#filterObject

display only matches



19
20
21
# File 'lib/glark/output/spec.rb', line 19

def filter
  @filter
end

#invert_matchObject

display non-matching lines



20
21
22
# File 'lib/glark/output/spec.rb', line 20

def invert_match
  @invert_match
end

#labelObject

Returns the value of attribute label.



21
22
23
# File 'lib/glark/output/spec.rb', line 21

def label
  @label
end

#match_limitObject

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

#outObject

Returns the value of attribute out.



23
24
25
# File 'lib/glark/output/spec.rb', line 23

def out
  @out
end

#show_file_namesObject

display file names



24
25
26
# File 'lib/glark/output/spec.rb', line 24

def show_file_names
  @show_file_names
end

#show_line_numbersObject

display numbers of matching lines



25
26
27
# File 'lib/glark/output/spec.rb', line 25

def show_line_numbers
  @show_line_numbers
end

#styleObject

grep, glark



29
30
31
# File 'lib/glark/output/spec.rb', line 29

def style
  @style
end

#write_nullObject

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_highlightObject



56
57
58
# File 'lib/glark/output/spec.rb', line 56

def file_highlight 
  @colors.file_name_color
end

#highlightObject



60
61
62
# File 'lib/glark/output/spec.rb', line 60

def highlight
  @colors.text_color_style
end

#line_number_highlightObject



52
53
54
# File 'lib/glark/output/spec.rb', line 52

def line_number_highlight
  @colors.line_number_color
end

#output_type_clsObject



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