Class: Flatito::Base

Inherits:
Object
  • Object
show all
Includes:
RegexFromSearch, Utils
Defined in:
lib/flatito/renderer.rb

Direct Known Subclasses

Renderer::Plain, Renderer::TTY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RegexFromSearch

#regex, #value_regex

Methods included from Utils

#truncate

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



23
24
25
26
27
28
29
# File 'lib/flatito/renderer.rb', line 23

def initialize(options)
  @no_color = options[:no_color] || false
  @search = options[:search]
  @search_value = options[:search_value]
  @case_sensitive = options[:case_sensitive]
  @no_color_resolved = nil
end

Instance Attribute Details

#case_sensitiveObject (readonly)

Returns the value of attribute case_sensitive.



21
22
23
# File 'lib/flatito/renderer.rb', line 21

def case_sensitive
  @case_sensitive
end

#no_colorObject (readonly)

Returns the value of attribute no_color.



21
22
23
# File 'lib/flatito/renderer.rb', line 21

def no_color
  @no_color
end

#searchObject (readonly)

Returns the value of attribute search.



21
22
23
# File 'lib/flatito/renderer.rb', line 21

def search
  @search
end

#search_valueObject (readonly)

Returns the value of attribute search_value.



21
22
23
# File 'lib/flatito/renderer.rb', line 21

def search_value
  @search_value
end

Instance Method Details

#endingObject



33
# File 'lib/flatito/renderer.rb', line 33

def ending; end

#prepareObject



31
# File 'lib/flatito/renderer.rb', line 31

def prepare; end


32
# File 'lib/flatito/renderer.rb', line 32

def print_file_progress(pathname); end


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/flatito/renderer.rb', line 49

def print_item(item, line_number_padding)
  line_number = colorize("#{item.line.to_s.rjust(line_number_padding)}: ", :yellow)
  value = if item.value.length.positive?
            display_value = truncate_value(item.value)
            colorize("=> ", :gray) + matched_value(display_value, :gray)
          else
            ""
          end

  stdout.puts "#{line_number} #{matched_string(item.key)} #{value}"
end


39
40
41
42
43
44
45
46
47
# File 'lib/flatito/renderer.rb', line 39

def print_items(items)
  line_number_padding = items.map(&:line).max.to_s.length

  items.each do |item|
    print_item(item, line_number_padding)
  end
  stdout.puts
  stdout.flush
end


35
36
37
# File 'lib/flatito/renderer.rb', line 35

def print_pathname(pathname)
  stdout.puts colorize(pathname.to_s, :light_blue)
end