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

Methods included from Utils

#truncate

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



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

def initialize(options)
  @no_color = options[:no_color] || false
  @search = options[:search]
end

Instance Attribute Details

#no_colorObject (readonly)

Returns the value of attribute no_color.



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

def no_color
  @no_color
end

#searchObject (readonly)

Returns the value of attribute search.



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

def search
  @search
end

Instance Method Details

#endingObject



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

def ending; end

#prepareObject



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

def prepare; end


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

def print_file_progress(pathname); end


47
48
49
50
51
52
53
54
55
56
# File 'lib/flatito/renderer.rb', line 47

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?
            colorize("=> #{item.value}", :gray)
          else
            ""
          end

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


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

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


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

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