File: abstract_output_stream.rb

package info (click to toggle)
ruby-zip 1.1.6-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 720 kB
  • ctags: 929
  • sloc: ruby: 7,045; makefile: 11
file content (45 lines) | stat: -rw-r--r-- 995 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
module Zip
  module IOExtras
    # Implements many of the output convenience methods of IO.
    # relies on <<
    module AbstractOutputStream
      include FakeIO

      def write(data)
        self << data
        data.to_s.bytesize
      end


      def print(*params)
        self << params.join($,) << $\.to_s
      end

      def printf(a_format_string, *params)
        self << sprintf(a_format_string, *params)
      end

      def putc(an_object)
        self << case an_object
                when Fixnum
                  an_object.chr
                when String
                  an_object
                else
                  raise TypeError, 'putc: Only Fixnum and String supported'
                end
        an_object
      end

      def puts(*params)
        params << "\n" if params.empty?
        params.flatten.each do |element|
          val = element.to_s
          self << val
          self << "\n" unless val[-1, 1] == "\n"
        end
      end

    end
  end
end