File: PrintFile.rb

package info (click to toggle)
quickfix 1.15.1%2Bdfsg-4
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 42,080 kB
  • sloc: cpp: 631,686; python: 129,549; ruby: 106,716; xml: 43,737; ansic: 7,668; java: 1,826; cs: 816; makefile: 544; sh: 462; sql: 313
file content (67 lines) | stat: -rw-r--r-- 963 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class PrintFile
  def initialize(name)
    @depth = 0
    @name = name
    @file = createFile(name)
  end

  def createFile(name)
    attr = File::CREAT|File::TRUNC|File::RDWR
    File.new(name, attr, 0644)
  end

  def tabs
    return "" if @depth == 0
    count = 0
    result = ""
    while (count != @depth)
      result += "  " 
      count += 1
    end
    return result
  end

  def indent
    @depth += 1
  end

  def dedent
    return if @depth == 0
    @depth -= 1
  end

  def printInline(*values)
    values.each do |value|
      @file.print(value)
    end
  end

  def putsInline(*values)
    @file.puts(values)
  end

  def print(*values)
    if(values.length == 0)
      return
    end

    @file.print tabs
    values.each do |value|
      @file.print(value)
    end
  end

  def puts(*values)
    if(values.length == 0)
      @file.puts
      return
    end

    @file.print tabs
    @file.puts values
  end

  def close
    @file.close
  end
end