steep 0.16.0 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +6 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep/project/file.rb +1 -1
  9. data/lib/steep/project/hover_content.rb +1 -1
  10. data/lib/steep/server/code_worker.rb +1 -1
  11. data/lib/steep/server/signature_worker.rb +4 -4
  12. data/lib/steep/type_construction.rb +10 -16
  13. data/lib/steep/type_inference/constant_env.rb +2 -10
  14. data/lib/steep/type_inference/context.rb +1 -0
  15. data/lib/steep/version.rb +1 -1
  16. data/steep.gemspec +1 -5
  17. metadata +17 -135
  18. data/exe/rbs +0 -3
  19. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  20. data/vendor/ruby-signature/.gitignore +0 -12
  21. data/vendor/ruby-signature/.rubocop.yml +0 -15
  22. data/vendor/ruby-signature/BSDL +0 -22
  23. data/vendor/ruby-signature/COPYING +0 -56
  24. data/vendor/ruby-signature/Gemfile +0 -6
  25. data/vendor/ruby-signature/README.md +0 -93
  26. data/vendor/ruby-signature/Rakefile +0 -142
  27. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
  28. data/vendor/ruby-signature/bin/console +0 -14
  29. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  30. data/vendor/ruby-signature/bin/setup +0 -10
  31. data/vendor/ruby-signature/bin/sort +0 -89
  32. data/vendor/ruby-signature/bin/test_runner.rb +0 -16
  33. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  34. data/vendor/ruby-signature/docs/sigs.md +0 -148
  35. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  36. data/vendor/ruby-signature/docs/syntax.md +0 -528
  37. data/vendor/ruby-signature/exe/rbs +0 -7
  38. data/vendor/ruby-signature/lib/rbs.rb +0 -64
  39. data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
  40. data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
  41. data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
  42. data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
  43. data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
  44. data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
  45. data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
  46. data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
  47. data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
  48. data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
  49. data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
  50. data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
  51. data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
  52. data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
  53. data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
  54. data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
  55. data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
  56. data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
  57. data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
  58. data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
  59. data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
  60. data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
  61. data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
  62. data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
  63. data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
  64. data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
  65. data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
  66. data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
  67. data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
  68. data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
  69. data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
  70. data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
  71. data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
  72. data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
  73. data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
  74. data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
  75. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
  76. data/vendor/ruby-signature/rbs.gemspec +0 -46
  77. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
  78. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
  79. data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
  80. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  81. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  82. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  83. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -45
  84. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  85. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  86. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  87. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  88. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  89. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  90. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -413
  91. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
  92. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  93. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  94. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  95. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  96. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -194
  97. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  98. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  99. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  100. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -1076
  101. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  102. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  103. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -243
  104. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  105. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
  106. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  107. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
  108. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
  109. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
  110. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
  111. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
  112. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
  113. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  114. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  115. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  116. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -429
  117. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
  118. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
  119. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  120. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  121. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -57
  122. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
  123. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  124. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  125. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1901
  126. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
  127. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  128. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
  129. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
  130. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  131. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
  132. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
  133. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  134. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
  135. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  136. data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
  137. data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
  138. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
  139. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
  140. data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
  141. data/vendor/ruby-signature/stdlib/json/json.rbs +0 -335
  142. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
  143. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  144. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  145. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  146. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -301
  147. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,17 +0,0 @@
1
- # The [Warning](Warning) module contains a single
2
- # method named [warn](Warning#method-i-warn), and the
3
- # module extends itself, making `Warning.warn` available.
4
- # [\#warn](Warning#method-i-warn) is called for all
5
- # warnings issued by Ruby. By default, warnings are printed to $stderr.
6
- #
7
- # By overriding [\#warn](Warning#method-i-warn), you
8
- # can change how warnings are handled by Ruby, either filtering some
9
- # warnings, and/or outputting warnings somewhere other than $stderr. When
10
- # [\#warn](Warning#method-i-warn) is overridden, super
11
- # can be called to get the default behavior of printing the warning to
12
- # $stderr.
13
- module Warning
14
- # Writes warning message msg to $stderr, followed by a newline if the message does not end in a newline.
15
- # This method is called by Ruby for all emitted warnings.
16
- def warn: (String) -> nil
17
- end
@@ -1,62 +0,0 @@
1
- # Coverage provides coverage measurement feature for Ruby. This feature is
2
- # experimental, so these APIs may be changed in future.
3
- #
4
- # # Usage
5
- #
6
- # 1. require "coverage"
7
- # 2. do Coverage.start
8
- # 3. require or load Ruby source file
9
- # 4. Coverage.result will return a hash that contains filename as key and
10
- # coverage array as value. A coverage array gives, for each line, the number
11
- # of line execution by the interpreter. A `nil` value means coverage is
12
- # disabled for this line (lines like `else` and `end`).
13
- #
14
- #
15
- # # Example
16
- #
17
- # [foo.rb]
18
- # s = 0
19
- # 10.times do |x|
20
- # s += x
21
- # end
22
- #
23
- # if s == 45
24
- # p :ok
25
- # else
26
- # p :ng
27
- # end
28
- # [EOF]
29
- #
30
- # require "coverage"
31
- # Coverage.start
32
- # require "foo.rb"
33
- # p Coverage.result #=> {"foo.rb"=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil]}
34
- #
35
- module Coverage
36
- def self.line_stub: () -> Array[Integer?]
37
-
38
- # Returns a hash that contains filename as key and coverage array as value. This
39
- # is the same as `Coverage.result(stop: false, clear: false)`.
40
- #
41
- # {
42
- # "file.rb" => [1, 2, nil],
43
- # ...
44
- # }
45
- #
46
- def self.peek_result: () -> Hash[String, untyped]
47
-
48
- # Returns a hash that contains filename as key and coverage array as value. If
49
- # `clear` is true, it clears the counters to zero. If `stop` is true, it
50
- # disables coverage measurement.
51
- #
52
- def self.result: (?stop: bool, ?clear: bool) -> Hash[String, untyped]
53
-
54
- # Returns true if coverage stats are currently being collected (after
55
- # Coverage.start call, but before Coverage.result call)
56
- #
57
- def self.running?: () -> bool
58
-
59
- # Enables coverage measurement.
60
- #
61
- def self.start: (?lines: bool, ?branches: bool, ?methods: bool, ?oneshot_lines: bool) -> nil
62
- end
@@ -1,773 +0,0 @@
1
- # This class provides a complete interface to CSV files and data. It offers
2
- # tools to enable you to read and write to and from Strings or IO objects, as
3
- # needed.
4
- #
5
- # The most generic interface of the library is:
6
- #
7
- # csv = CSV.new(string_or_io, **options)
8
- #
9
- # # Reading: IO object should be open for read
10
- # csv.read # => array of rows
11
- # # or
12
- # csv.each do |row|
13
- # # ...
14
- # end
15
- # # or
16
- # row = csv.shift
17
- #
18
- # # Writing: IO object should be open for write
19
- # csv << row
20
- #
21
- # There are several specialized class methods for one-statement reading or
22
- # writing, described in the Specialized Methods section.
23
- #
24
- # If a String is passed into ::new, it is internally wrapped into a StringIO
25
- # object.
26
- #
27
- # `options` can be used for specifying the particular CSV flavor (column
28
- # separators, row separators, value quoting and so on), and for data conversion,
29
- # see Data Conversion section for the description of the latter.
30
- #
31
- # ## Specialized Methods
32
- #
33
- # ### Reading
34
- #
35
- # # From a file: all at once
36
- # arr_of_rows = CSV.read("path/to/file.csv", **options)
37
- # # iterator-style:
38
- # CSV.foreach("path/to/file.csv", **options) do |row|
39
- # # ...
40
- # end
41
- #
42
- # # From a string
43
- # arr_of_rows = CSV.parse("CSV,data,String", **options)
44
- # # or
45
- # CSV.parse("CSV,data,String", **options) do |row|
46
- # # ...
47
- # end
48
- #
49
- # ### Writing
50
- #
51
- # # To a file
52
- # CSV.open("path/to/file.csv", "wb") do |csv|
53
- # csv << ["row", "of", "CSV", "data"]
54
- # csv << ["another", "row"]
55
- # # ...
56
- # end
57
- #
58
- # # To a String
59
- # csv_string = CSV.generate do |csv|
60
- # csv << ["row", "of", "CSV", "data"]
61
- # csv << ["another", "row"]
62
- # # ...
63
- # end
64
- #
65
- # ### Shortcuts
66
- #
67
- # # Core extensions for converting one line
68
- # csv_string = ["CSV", "data"].to_csv # to CSV
69
- # csv_array = "CSV,String".parse_csv # from CSV
70
- #
71
- # # CSV() method
72
- # CSV { |csv_out| csv_out << %w{my data here} } # to $stdout
73
- # CSV(csv = "") { |csv_str| csv_str << %w{my data here} } # to a String
74
- # CSV($stderr) { |csv_err| csv_err << %w{my data here} } # to $stderr
75
- # CSV($stdin) { |csv_in| csv_in.each { |row| p row } } # from $stdin
76
- #
77
- # ## Data Conversion
78
- #
79
- # ### CSV with headers
80
- #
81
- # CSV allows to specify column names of CSV file, whether they are in data, or
82
- # provided separately. If headers are specified, reading methods return an
83
- # instance of CSV::Table, consisting of CSV::Row.
84
- #
85
- # # Headers are part of data
86
- # data = CSV.parse(<<~ROWS, headers: true)
87
- # Name,Department,Salary
88
- # Bob,Engineering,1000
89
- # Jane,Sales,2000
90
- # John,Management,5000
91
- # ROWS
92
- #
93
- # data.class #=> CSV::Table
94
- # data.first #=> #<CSV::Row "Name":"Bob" "Department":"Engineering" "Salary":"1000">
95
- # data.first.to_h #=> {"Name"=>"Bob", "Department"=>"Engineering", "Salary"=>"1000"}
96
- #
97
- # # Headers provided by developer
98
- # data = CSV.parse('Bob,Engineering,1000', headers: %i[name department salary])
99
- # data.first #=> #<CSV::Row name:"Bob" department:"Engineering" salary:"1000">
100
- #
101
- # ### Typed data reading
102
- #
103
- # CSV allows to provide a set of data *converters* e.g. transformations to try
104
- # on input data. Converter could be a symbol from CSV::Converters constant's
105
- # keys, or lambda.
106
- #
107
- # # Without any converters:
108
- # CSV.parse('Bob,2018-03-01,100')
109
- # #=> [["Bob", "2018-03-01", "100"]]
110
- #
111
- # # With built-in converters:
112
- # CSV.parse('Bob,2018-03-01,100', converters: %i[numeric date])
113
- # #=> [["Bob", #<Date: 2018-03-01>, 100]]
114
- #
115
- # # With custom converters:
116
- # CSV.parse('Bob,2018-03-01,100', converters: [->(v) { Time.parse(v) rescue v }])
117
- # #=> [["Bob", 2018-03-01 00:00:00 +0200, "100"]]
118
- #
119
- # ## CSV and Character Encodings (M17n or Multilingualization)
120
- #
121
- # This new CSV parser is m17n savvy. The parser works in the Encoding of the IO
122
- # or String object being read from or written to. Your data is never transcoded
123
- # (unless you ask Ruby to transcode it for you) and will literally be parsed in
124
- # the Encoding it is in. Thus CSV will return Arrays or Rows of Strings in the
125
- # Encoding of your data. This is accomplished by transcoding the parser itself
126
- # into your Encoding.
127
- #
128
- # Some transcoding must take place, of course, to accomplish this multiencoding
129
- # support. For example, `:col_sep`, `:row_sep`, and `:quote_char` must be
130
- # transcoded to match your data. Hopefully this makes the entire process feel
131
- # transparent, since CSV's defaults should just magically work for your data.
132
- # However, you can set these values manually in the target Encoding to avoid the
133
- # translation.
134
- #
135
- # It's also important to note that while all of CSV's core parser is now
136
- # Encoding agnostic, some features are not. For example, the built-in converters
137
- # will try to transcode data to UTF-8 before making conversions. Again, you can
138
- # provide custom converters that are aware of your Encodings to avoid this
139
- # translation. It's just too hard for me to support native conversions in all of
140
- # Ruby's Encodings.
141
- #
142
- # Anyway, the practical side of this is simple: make sure IO and String objects
143
- # passed into CSV have the proper Encoding set and everything should just work.
144
- # CSV methods that allow you to open IO objects (CSV::foreach(), CSV::open(),
145
- # CSV::read(), and CSV::readlines()) do allow you to specify the Encoding.
146
- #
147
- # One minor exception comes when generating CSV into a String with an Encoding
148
- # that is not ASCII compatible. There's no existing data for CSV to use to
149
- # prepare itself and thus you will probably need to manually specify the desired
150
- # Encoding for most of those cases. It will try to guess using the fields in a
151
- # row of output though, when using CSV::generate_line() or Array#to_csv().
152
- #
153
- # I try to point out any other Encoding issues in the documentation of methods
154
- # as they come up.
155
- #
156
- # This has been tested to the best of my ability with all non-"dummy" Encodings
157
- # Ruby ships with. However, it is brave new code and may have some bugs. Please
158
- # feel free to [report](mailto:james@grayproductions.net) any issues you find
159
- # with it.
160
- #
161
- class CSV < Object
162
- include Enumerable
163
-
164
- # This method is intended as the primary interface for reading CSV files. You
165
- # pass a `path` and any `options` you wish to set for the read. Each row of file
166
- # will be passed to the provided `block` in turn.
167
- #
168
- # The `options` parameter can be anything CSV::new() understands. This method
169
- # also understands an additional `:encoding` parameter that you can use to
170
- # specify the Encoding of the data in the file to be read. You must provide this
171
- # unless your data is in Encoding::default_external(). CSV will use this to
172
- # determine how to parse the data. You may provide a second Encoding to have the
173
- # data transcoded as it is read. For example, `encoding: "UTF-32BE:UTF-8"` would
174
- # read UTF-32BE data from the file but transcode it to UTF-8 before CSV parses
175
- # it.
176
- #
177
- def self.foreach: [U] (String | IO | StringIO path, ?::Hash[Symbol, U] options) { (::Array[String?] arg0) -> void } -> void
178
-
179
- # This constructor will wrap either a String or IO object passed in `data` for
180
- # reading and/or writing. In addition to the CSV instance methods, several IO
181
- # methods are delegated. (See CSV::open() for a complete list.) If you pass a
182
- # String for `data`, you can later retrieve it (after writing to it, for
183
- # example) with CSV.string().
184
- #
185
- # Note that a wrapped String will be positioned at the beginning (for reading).
186
- # If you want it at the end (for writing), use CSV::generate(). If you want any
187
- # other positioning, pass a preset StringIO object instead.
188
- #
189
- # You may set any reading and/or writing preferences in the `options` Hash.
190
- # Available options are:
191
- #
192
- # **`:col_sep`**
193
- # : The String placed between each field. This String will be transcoded into
194
- # the data's Encoding before parsing.
195
- # **`:row_sep`**
196
- # : The String appended to the end of each row. This can be set to the special
197
- # `:auto` setting, which requests that CSV automatically discover this from
198
- # the data. Auto-discovery reads ahead in the data looking for the next
199
- # `"\r\n"`, `"\n"`, or `"\r"` sequence. A sequence will be selected even if
200
- # it occurs in a quoted field, assuming that you would have the same line
201
- # endings there. If none of those sequences is found, `data` is `ARGF`,
202
- # `STDIN`, `STDOUT`, or `STDERR`, or the stream is only available for
203
- # output, the default `$INPUT_RECORD_SEPARATOR` (`$/`) is used. Obviously,
204
- # discovery takes a little time. Set manually if speed is important. Also
205
- # note that IO objects should be opened in binary mode on Windows if this
206
- # feature will be used as the line-ending translation can cause problems
207
- # with resetting the document position to where it was before the read
208
- # ahead. This String will be transcoded into the data's Encoding before
209
- # parsing.
210
- # **`:quote_char`**
211
- # : The character used to quote fields. This has to be a single character
212
- # String. This is useful for application that incorrectly use `'` as the
213
- # quote character instead of the correct `"`. CSV will always consider a
214
- # double sequence of this character to be an escaped quote. This String will
215
- # be transcoded into the data's Encoding before parsing.
216
- # **`:field_size_limit`**
217
- # : This is a maximum size CSV will read ahead looking for the closing quote
218
- # for a field. (In truth, it reads to the first line ending beyond this
219
- # size.) If a quote cannot be found within the limit CSV will raise a
220
- # MalformedCSVError, assuming the data is faulty. You can use this limit to
221
- # prevent what are effectively DoS attacks on the parser. However, this
222
- # limit can cause a legitimate parse to fail and thus is set to `nil`, or
223
- # off, by default.
224
- # **`:converters`**
225
- # : An Array of names from the Converters Hash and/or lambdas that handle
226
- # custom conversion. A single converter doesn't have to be in an Array. All
227
- # built-in converters try to transcode fields to UTF-8 before converting.
228
- # The conversion will fail if the data cannot be transcoded, leaving the
229
- # field unchanged.
230
- # **`:unconverted_fields`**
231
- # : If set to `true`, an unconverted_fields() method will be added to all
232
- # returned rows (Array or CSV::Row) that will return the fields as they were
233
- # before conversion. Note that `:headers` supplied by Array or String were
234
- # not fields of the document and thus will have an empty Array attached.
235
- # **`:headers`**
236
- # : If set to `:first_row` or `true`, the initial row of the CSV file will be
237
- # treated as a row of headers. If set to an Array, the contents will be used
238
- # as the headers. If set to a String, the String is run through a call of
239
- # CSV::parse_line() with the same `:col_sep`, `:row_sep`, and `:quote_char`
240
- # as this instance to produce an Array of headers. This setting causes
241
- # CSV#shift() to return rows as CSV::Row objects instead of Arrays and
242
- # CSV#read() to return CSV::Table objects instead of an Array of Arrays.
243
- # **`:return_headers`**
244
- # : When `false`, header rows are silently swallowed. If set to `true`, header
245
- # rows are returned in a CSV::Row object with identical headers and fields
246
- # (save that the fields do not go through the converters).
247
- # **`:write_headers`**
248
- # : When `true` and `:headers` is set, a header row will be added to the
249
- # output.
250
- # **`:header_converters`**
251
- # : Identical in functionality to `:converters` save that the conversions are
252
- # only made to header rows. All built-in converters try to transcode headers
253
- # to UTF-8 before converting. The conversion will fail if the data cannot be
254
- # transcoded, leaving the header unchanged.
255
- # **`:skip_blanks`**
256
- # : When setting a `true` value, CSV will skip over any empty rows. Note that
257
- # this setting will not skip rows that contain column separators, even if
258
- # the rows contain no actual data. If you want to skip rows that contain
259
- # separators but no content, consider using `:skip_lines`, or inspecting
260
- # fields.compact.empty? on each row.
261
- # **`:force_quotes`**
262
- # : When setting a `true` value, CSV will quote all CSV fields it creates.
263
- # **`:skip_lines`**
264
- # : When setting an object responding to `match`, every line matching it is
265
- # considered a comment and ignored during parsing. When set to a String, it
266
- # is first converted to a Regexp. When set to `nil` no line is considered a
267
- # comment. If the passed object does not respond to `match`, `ArgumentError`
268
- # is thrown.
269
- # **`:liberal_parsing`**
270
- # : When setting a `true` value, CSV will attempt to parse input not
271
- # conformant with RFC 4180, such as double quotes in unquoted fields.
272
- # **`:nil_value`**
273
- # : When set an object, any values of an empty field is replaced by the set
274
- # object, not nil.
275
- # **`:empty_value`**
276
- # : When setting an object, any values of a blank string field is replaced by
277
- # the set object.
278
- # **`:quote_empty`**
279
- # : When setting a `true` value, CSV will quote empty values with double
280
- # quotes. When `false`, CSV will emit an empty string for an empty field
281
- # value.
282
- # **`:write_converters`**
283
- # : Converts values on each line with the specified `Proc` object(s), which
284
- # receive a `String` value and return a `String` or `nil` value. When an
285
- # array is specified, each converter will be applied in order.
286
- # **`:write_nil_value`**
287
- # : When a `String` value, `nil` value(s) on each line will be replaced with
288
- # the specified value.
289
- # **`:write_empty_value`**
290
- # : When a `String` or `nil` value, empty value(s) on each line will be
291
- # replaced with the specified value.
292
- # **`:strip`**
293
- # : When setting a `true` value, CSV will strip "t\r\n\f\v" around the values.
294
- # If you specify a string instead of `true`, CSV will strip string. The
295
- # length of the string must be 1.
296
- #
297
- #
298
- # See CSV::DEFAULT_OPTIONS for the default settings.
299
- #
300
- # Options cannot be overridden in the instance methods for performance reasons,
301
- # so be sure to set what you want here.
302
- def initialize: (?String | IO | StringIO io, ?::Hash[Symbol, untyped] options) -> void
303
-
304
- # This method can be used to easily parse CSV out of a String. You may either
305
- # provide a `block` which will be called with each row of the String in turn, or
306
- # just use the returned Array of Arrays (when no `block` is given).
307
- #
308
- # You pass your `str` to read from, and an optional `options` containing
309
- # anything CSV::new() understands.
310
- #
311
- def self.parse: (String str, ?::Hash[Symbol, untyped] options) ?{ (::Array[String?] arg0) -> void } -> ::Array[::Array[String?]]?
312
-
313
- # This method is a shortcut for converting a single line of a CSV String into an
314
- # Array. Note that if `line` contains multiple rows, anything beyond the first
315
- # row is ignored.
316
- #
317
- # The `options` parameter can be anything CSV::new() understands.
318
- #
319
- def self.parse_line: (String str, ?::Hash[Symbol, untyped] options) -> ::Array[String?]?
320
-
321
- # Slurps the remaining rows and returns an Array of Arrays.
322
- #
323
- # The data source must be open for reading.
324
- #
325
- def read: () -> ::Array[::Array[String?]]
326
-
327
- def readline: () -> ::Array[String?]?
328
-
329
- # Use to slurp a CSV file into an Array of Arrays. Pass the `path` to the file
330
- # and any `options` CSV::new() understands. This method also understands an
331
- # additional `:encoding` parameter that you can use to specify the Encoding of
332
- # the data in the file to be read. You must provide this unless your data is in
333
- # Encoding::default_external(). CSV will use this to determine how to parse the
334
- # data. You may provide a second Encoding to have the data transcoded as it is
335
- # read. For example, `encoding: "UTF-32BE:UTF-8"` would read UTF-32BE data from
336
- # the file but transcode it to UTF-8 before CSV parses it.
337
- #
338
- def self.read: (String path, ?::Hash[Symbol, untyped] options) -> ::Array[::Array[String?]]
339
-
340
- # The primary write method for wrapped Strings and IOs, `row` (an Array or
341
- # CSV::Row) is converted to CSV and appended to the data source. When a CSV::Row
342
- # is passed, only the row's fields() are appended to the output.
343
- #
344
- # The data source must be open for writing.
345
- #
346
- def <<: (::Array[untyped] | CSV::Row row) -> void
347
-
348
- # This method wraps a String you provide, or an empty default String, in a CSV
349
- # object which is passed to the provided block. You can use the block to append
350
- # CSV rows to the String and when the block exits, the final String will be
351
- # returned.
352
- #
353
- # Note that a passed String **is** modified by this method. Call dup() before
354
- # passing if you need a new String.
355
- #
356
- # The `options` parameter can be anything CSV::new() understands. This method
357
- # understands an additional `:encoding` parameter when not passed a String to
358
- # set the base Encoding for the output. CSV needs this hint if you plan to
359
- # output non-ASCII compatible data.
360
- #
361
- def self.generate: (?String str, **untyped options) { (CSV csv) -> void } -> String
362
- end
363
-
364
- # The options used when no overrides are given by calling code. They are:
365
- #
366
- # **`:col_sep`**
367
- # : `","`
368
- # **`:row_sep`**
369
- # : `:auto`
370
- # **`:quote_char`**
371
- # : `'"'`
372
- # **`:field_size_limit`**
373
- # : `nil`
374
- # **`:converters`**
375
- # : `nil`
376
- # **`:unconverted_fields`**
377
- # : `nil`
378
- # **`:headers`**
379
- # : `false`
380
- # **`:return_headers`**
381
- # : `false`
382
- # **`:header_converters`**
383
- # : `nil`
384
- # **`:skip_blanks`**
385
- # : `false`
386
- # **`:force_quotes`**
387
- # : `false`
388
- # **`:skip_lines`**
389
- # : `nil`
390
- # **`:liberal_parsing`**
391
- # : `false`
392
- # **`:quote_empty`**
393
- # : `true`
394
- #
395
- #
396
- CSV::DEFAULT_OPTIONS: ::Hash[untyped, untyped]
397
-
398
- # The version of the installed library.
399
- #
400
- CSV::VERSION: String
401
-
402
- # A CSV::Row is part Array and part Hash. It retains an order for the fields and
403
- # allows duplicates just as an Array would, but also allows you to access fields
404
- # by name just as you could if they were in a Hash.
405
- #
406
- # All rows returned by CSV will be constructed from this class, if header row
407
- # processing is activated.
408
- #
409
- class CSV::Row < Object
410
- include Enumerable
411
-
412
- # If a two-element Array is provided, it is assumed to be a header and field and
413
- # the pair is appended. A Hash works the same way with the key being the header
414
- # and the value being the field. Anything else is assumed to be a lone field
415
- # which is appended with a `nil` header.
416
- #
417
- # This method returns the row for chaining.
418
- #
419
- def <<: (untyped arg) -> untyped
420
-
421
- # Returns `true` if this row contains the same headers and fields in the same
422
- # order as `other`.
423
- #
424
- def ==: (untyped other) -> bool
425
-
426
- alias [] field
427
-
428
- # Looks up the field by the semantics described in CSV::Row.field() and assigns
429
- # the `value`.
430
- #
431
- # Assigning past the end of the row with an index will set all pairs between to
432
- # `[nil, nil]`. Assigning to an unused header appends the new pair.
433
- #
434
- def []=: (*untyped args) -> untyped
435
-
436
- # Removes a pair from the row by `header` or `index`. The pair is located as
437
- # described in CSV::Row.field(). The deleted pair is returned, or `nil` if a
438
- # pair could not be found.
439
- #
440
- def delete: (untyped header_or_index, ?untyped minimum_index) -> untyped
441
-
442
- # The provided `block` is passed a header and field for each pair in the row and
443
- # expected to return `true` or `false`, depending on whether the pair should be
444
- # deleted.
445
- #
446
- # This method returns the row for chaining.
447
- #
448
- # If no block is given, an Enumerator is returned.
449
- #
450
- def delete_if: () { (*untyped) -> untyped } -> untyped
451
-
452
- # Extracts the nested value specified by the sequence of `index` or `header`
453
- # objects by calling dig at each step, returning nil if any intermediate step is
454
- # nil.
455
- #
456
- def dig: (untyped index_or_header, *untyped indexes) -> untyped
457
-
458
- # Yields each pair of the row as header and field tuples (much like iterating
459
- # over a Hash). This method returns the row for chaining.
460
- #
461
- # If no block is given, an Enumerator is returned.
462
- #
463
- # Support for Enumerable.
464
- #
465
- def each: () { (*untyped) -> untyped } -> untyped
466
-
467
- alias each_pair each
468
-
469
- def empty?: (*untyped args) { (*untyped) -> untyped } -> bool
470
-
471
- # This method will fetch the field value by `header`. It has the same behavior
472
- # as Hash#fetch: if there is a field with the given `header`, its value is
473
- # returned. Otherwise, if a block is given, it is yielded the `header` and its
474
- # result is returned; if a `default` is given as the second argument, it is
475
- # returned; otherwise a KeyError is raised.
476
- #
477
- def fetch: (untyped header, *untyped varargs) ?{ (*untyped) -> untyped } -> untyped
478
-
479
- # This method will return the field value by `header` or `index`. If a field is
480
- # not found, `nil` is returned.
481
- #
482
- # When provided, `offset` ensures that a header match occurs on or later than
483
- # the `offset` index. You can use this to find duplicate headers, without
484
- # resorting to hard-coding exact indices.
485
- #
486
- def field: (untyped header_or_index, ?untyped minimum_index) -> untyped
487
-
488
- # Returns `true` if `data` matches a field in this row, and `false` otherwise.
489
- #
490
- def field?: (untyped data) -> bool
491
-
492
- # Returns `true` if this is a field row.
493
- #
494
- def field_row?: () -> bool
495
-
496
- # This method accepts any number of arguments which can be headers, indices,
497
- # Ranges of either, or two-element Arrays containing a header and offset. Each
498
- # argument will be replaced with a field lookup as described in
499
- # CSV::Row.field().
500
- #
501
- # If called with no arguments, all fields are returned.
502
- #
503
- def fields: (*untyped headers_and_or_indices) -> untyped
504
-
505
- # Returns `true` if there is a field with the given `header`.
506
- #
507
- def has_key?: (untyped header) -> bool
508
-
509
- alias header? has_key?
510
-
511
- # Returns `true` if this is a header row.
512
- #
513
- def header_row?: () -> bool
514
-
515
- # Returns the headers of this row.
516
- #
517
- def headers: () -> untyped
518
-
519
- alias include? has_key?
520
-
521
- # This method will return the index of a field with the provided `header`. The
522
- # `offset` can be used to locate duplicate header names, as described in
523
- # CSV::Row.field().
524
- #
525
- def index: (untyped header, ?untyped minimum_index) -> untyped
526
-
527
- # A summary of fields, by header, in an ASCII compatible String.
528
- #
529
- def inspect: () -> String
530
-
531
- alias key? has_key?
532
-
533
- def length: (*untyped args) { (*untyped) -> untyped } -> untyped
534
-
535
- alias member? has_key?
536
-
537
- # A shortcut for appending multiple fields. Equivalent to:
538
- #
539
- # args.each { |arg| csv_row << arg }
540
- #
541
- # This method returns the row for chaining.
542
- #
543
- def push: (*untyped args) -> untyped
544
-
545
- def size: (*untyped args) { (*untyped) -> untyped } -> untyped
546
-
547
- alias to_ary to_a
548
-
549
- # Returns the row as a CSV String. Headers are not used. Equivalent to:
550
- #
551
- # csv_row.fields.to_csv( options )
552
- #
553
- def to_csv: (**untyped) -> untyped
554
-
555
- # Collapses the row into a simple Hash. Be warned that this discards field order
556
- # and clobbers duplicate fields.
557
- #
558
- def to_h: () -> untyped
559
-
560
- alias to_hash to_h
561
-
562
- alias to_s to_csv
563
-
564
- alias values_at fields
565
- end
566
-
567
- class CSV::FieldInfo < Struct
568
- end
569
-
570
- # The error thrown when the parser encounters illegal CSV formatting.
571
- #
572
- class CSV::MalformedCSVError < RuntimeError
573
- end
574
-
575
- # A CSV::Table is a two-dimensional data structure for representing CSV
576
- # documents. Tables allow you to work with the data by row or column, manipulate
577
- # the data, and even convert the results back to CSV, if needed.
578
- #
579
- # All tables returned by CSV will be constructed from this class, if header row
580
- # processing is activated.
581
- #
582
- class CSV::Table[out Elem] < Object
583
- include Enumerable
584
-
585
- # Constructs a new CSV::Table from `array_of_rows`, which are expected to be
586
- # CSV::Row objects. All rows are assumed to have the same headers.
587
- #
588
- # The optional `headers` parameter can be set to Array of headers. If headers
589
- # aren't set, headers are fetched from CSV::Row objects. Otherwise, headers()
590
- # method will return headers being set in headers argument.
591
- #
592
- # A CSV::Table object supports the following Array methods through delegation:
593
- #
594
- # * empty?()
595
- # * length()
596
- # * size()
597
- #
598
- def initialize: (untyped array_of_rows, ?headers: untyped) -> untyped
599
-
600
- # Adds a new row to the bottom end of this table. You can provide an Array,
601
- # which will be converted to a CSV::Row (inheriting the table's headers()), or a
602
- # CSV::Row.
603
- #
604
- # This method returns the table for chaining.
605
- #
606
- def <<: (untyped row_or_array) -> untyped
607
-
608
- # Returns `true` if all rows of this table ==() `other`'s rows.
609
- #
610
- def ==: (untyped other) -> bool
611
-
612
- # In the default mixed mode, this method returns rows for index access and
613
- # columns for header access. You can force the index association by first
614
- # calling by_col!() or by_row!().
615
- #
616
- # Columns are returned as an Array of values. Altering that Array has no effect
617
- # on the table.
618
- #
619
- def []: (untyped index_or_header) -> untyped
620
-
621
- # In the default mixed mode, this method assigns rows for index access and
622
- # columns for header access. You can force the index association by first
623
- # calling by_col!() or by_row!().
624
- #
625
- # Rows may be set to an Array of values (which will inherit the table's
626
- # headers()) or a CSV::Row.
627
- #
628
- # Columns may be set to a single value, which is copied to each row of the
629
- # column, or an Array of values. Arrays of values are assigned to rows top to
630
- # bottom in row major order. Excess values are ignored and if the Array does not
631
- # have a value for each row the extra rows will receive a `nil`.
632
- #
633
- # Assigning to an existing column or row clobbers the data. Assigning to new
634
- # columns creates them at the right end of the table.
635
- #
636
- def []=: (untyped index_or_header, untyped value) -> untyped
637
-
638
- # Returns a duplicate table object, in column mode. This is handy for chaining
639
- # in a single call without changing the table mode, but be aware that this
640
- # method can consume a fair amount of memory for bigger data sets.
641
- #
642
- # This method returns the duplicate table for chaining. Don't chain destructive
643
- # methods (like []=()) this way though, since you are working with a duplicate.
644
- #
645
- def by_col: () -> untyped
646
-
647
- # Switches the mode of this table to column mode. All calls to indexing and
648
- # iteration methods will work with columns until the mode is changed again.
649
- #
650
- # This method returns the table and is safe to chain.
651
- #
652
- def by_col!: () -> untyped
653
-
654
- # Returns a duplicate table object, in mixed mode. This is handy for chaining in
655
- # a single call without changing the table mode, but be aware that this method
656
- # can consume a fair amount of memory for bigger data sets.
657
- #
658
- # This method returns the duplicate table for chaining. Don't chain destructive
659
- # methods (like []=()) this way though, since you are working with a duplicate.
660
- #
661
- def by_col_or_row: () -> untyped
662
-
663
- # Switches the mode of this table to mixed mode. All calls to indexing and
664
- # iteration methods will use the default intelligent indexing system until the
665
- # mode is changed again. In mixed mode an index is assumed to be a row reference
666
- # while anything else is assumed to be column access by headers.
667
- #
668
- # This method returns the table and is safe to chain.
669
- #
670
- def by_col_or_row!: () -> untyped
671
-
672
- # Returns a duplicate table object, in row mode. This is handy for chaining in
673
- # a single call without changing the table mode, but be aware that this method
674
- # can consume a fair amount of memory for bigger data sets.
675
- #
676
- # This method returns the duplicate table for chaining. Don't chain destructive
677
- # methods (like []=()) this way though, since you are working with a duplicate.
678
- #
679
- def by_row: () -> untyped
680
-
681
- # Switches the mode of this table to row mode. All calls to indexing and
682
- # iteration methods will work with rows until the mode is changed again.
683
- #
684
- # This method returns the table and is safe to chain.
685
- #
686
- def by_row!: () -> untyped
687
-
688
- # Removes and returns the indicated columns or rows. In the default mixed mode
689
- # indices refer to rows and everything else is assumed to be a column headers.
690
- # Use by_col!() or by_row!() to force the lookup.
691
- #
692
- def delete: (*untyped indexes_or_headers) -> untyped
693
-
694
- # Removes any column or row for which the block returns `true`. In the default
695
- # mixed mode or row mode, iteration is the standard row major walking of rows.
696
- # In column mode, iteration will `yield` two element tuples containing the
697
- # column name and an Array of values for that column.
698
- #
699
- # This method returns the table for chaining.
700
- #
701
- # If no block is given, an Enumerator is returned.
702
- #
703
- def delete_if: () { (*untyped) -> untyped } -> untyped
704
-
705
- # Extracts the nested value specified by the sequence of `index` or `header`
706
- # objects by calling dig at each step, returning nil if any intermediate step is
707
- # nil.
708
- #
709
- def dig: (untyped index_or_header, *untyped index_or_headers) -> untyped
710
-
711
- # In the default mixed mode or row mode, iteration is the standard row major
712
- # walking of rows. In column mode, iteration will `yield` two element tuples
713
- # containing the column name and an Array of values for that column.
714
- #
715
- # This method returns the table for chaining.
716
- #
717
- # If no block is given, an Enumerator is returned.
718
- #
719
- def each: () { (*untyped) -> untyped } -> untyped
720
-
721
- def empty?: (*untyped args) { (*untyped) -> untyped } -> untyped
722
-
723
- # Returns the headers for the first row of this table (assumed to match all
724
- # other rows). The headers Array passed to CSV::Table.new is returned for empty
725
- # tables.
726
- #
727
- def headers: () -> untyped
728
-
729
- # Shows the mode and size of this table in a US-ASCII String.
730
- #
731
- def inspect: () -> String
732
-
733
- def length: (*untyped args) { (*untyped) -> untyped } -> untyped
734
-
735
- # The current access mode for indexing and iteration.
736
- #
737
- def mode: () -> untyped
738
-
739
- # A shortcut for appending multiple rows. Equivalent to:
740
- #
741
- # rows.each { |row| self << row }
742
- #
743
- # This method returns the table for chaining.
744
- #
745
- def push: (*untyped rows) -> untyped
746
-
747
- def size: (*untyped args) { (*untyped) -> untyped } -> untyped
748
-
749
- # Returns the table as an Array of Arrays. Headers will be the first row, then
750
- # all of the field rows will follow.
751
- #
752
- def to_a: () -> untyped
753
-
754
- # Returns the table as a complete CSV String. Headers will be listed first, then
755
- # all of the field rows.
756
- #
757
- # This method assumes you want the Table.headers(), unless you explicitly pass
758
- # `:write_headers => false`.
759
- #
760
- def to_csv: (?write_headers: bool, **untyped) -> untyped
761
-
762
- alias to_s to_csv
763
-
764
- # The mixed mode default is to treat a list of indices as row access, returning
765
- # the rows indicated. Anything else is considered columnar access. For columnar
766
- # access, the return set has an Array for each row with the values indicated by
767
- # the headers in each Array. You can force column or row mode using by_col!() or
768
- # by_row!().
769
- #
770
- # You cannot mix column and row access.
771
- #
772
- def values_at: (*untyped indices_or_headers) -> untyped
773
- end