osv 0.3.10 → 0.3.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +50 -42
- data/Rakefile +3 -2
- data/lib/osv/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 593a3c94b6ec0366399485444f4d5d6c45b04393cad30686e04b43f289b93d88
|
4
|
+
data.tar.gz: 9ae3ce1ff2655d65c726680a412336e853f3fa0328756b5dea69186b2c82654b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a24c9b58b291d934ae6526e88baddebd768ad4ad431bfab8353b84d4e9f284e954aa2dd80b11138c041613702d56927f3fc4819b9fdcda2a22b5a590ba5459fa
|
7
|
+
data.tar.gz: 0a85ef04fc18b4ef680d669c4fb06310b0cd3a0eb2c6c3c5a0a9161bc5af8b8851bf7ca3c1cb08f3fc6fa2d96449e112b86d0bc47871cbd10cae5ebd332edfb4
|
data/README.md
CHANGED
@@ -30,38 +30,68 @@ gem install osv
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
-
###
|
34
|
-
|
35
|
-
Each row is returned as a hash where the keys are the column headers:
|
33
|
+
### Reading CSV Files
|
36
34
|
|
37
35
|
```ruby
|
38
36
|
require 'osv'
|
39
37
|
|
40
|
-
#
|
41
|
-
OSV.for_each("
|
42
|
-
|
43
|
-
puts row["
|
38
|
+
# Basic usage - each row as a hash
|
39
|
+
OSV.for_each("data.csv") do |row|
|
40
|
+
puts row["name"] # => "John"
|
41
|
+
puts row["age"] # => "25"
|
44
42
|
end
|
45
43
|
|
46
|
-
#
|
47
|
-
rows = OSV.for_each("
|
44
|
+
# Return an enumerator instead of using a block
|
45
|
+
rows = OSV.for_each("data.csv")
|
48
46
|
rows.each { |row| puts row["name"] }
|
49
|
-
```
|
50
47
|
|
51
|
-
|
48
|
+
# High-performance array mode
|
49
|
+
OSV.for_each("data.csv", result_type: :array) do |row|
|
50
|
+
puts row[0] # First column
|
51
|
+
puts row[1] # Second column
|
52
|
+
end
|
53
|
+
```
|
52
54
|
|
53
|
-
|
55
|
+
### Input Sources
|
54
56
|
|
55
57
|
```ruby
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
# From a file path
|
59
|
+
OSV.for_each("data.csv") { |row| puts row["name"] }
|
60
|
+
|
61
|
+
# From a file path
|
62
|
+
OSV.for_each("data.csv.gz") { |row| puts row["name"] }
|
63
|
+
|
64
|
+
# From an IO object
|
65
|
+
File.open("data.csv") { |file| OSV.for_each(file) { |row| puts row["name"] } }
|
66
|
+
|
67
|
+
# From a string
|
68
|
+
data = StringIO.new("name,age\nJohn,25")
|
69
|
+
OSV.for_each(data) { |row| puts row["name"] }
|
60
70
|
```
|
61
71
|
|
62
|
-
### Options
|
72
|
+
### Configuration Options
|
63
73
|
|
64
|
-
|
74
|
+
```ruby
|
75
|
+
OSV.for_each("data.csv",
|
76
|
+
# Input formatting
|
77
|
+
has_headers: true, # First row contains headers (default: true)
|
78
|
+
col_sep: ",", # Column separator (default: ",")
|
79
|
+
quote_char: '"', # Quote character (default: '"')
|
80
|
+
|
81
|
+
# Output formatting
|
82
|
+
result_type: :hash, # :hash or :array (hash is default)
|
83
|
+
nil_string: nil, # String to interpret as nil when parsing (default: nil)
|
84
|
+
|
85
|
+
# Parsing behavior
|
86
|
+
flexible: false, # Allow varying number of fields (default: false)
|
87
|
+
flexible_default: nil, # Default value for missing fields. If unset, we ignore missing fields.
|
88
|
+
# Implicitly enables flexible mode if set.
|
89
|
+
trim: :all, # Whether to trim whitespace. Options are :all, :headers, or :fields (default: nil)
|
90
|
+
buffer_size: 1024, # Number of rows to buffer in memory (default: 1024)
|
91
|
+
)
|
92
|
+
```
|
93
|
+
|
94
|
+
#### Available Options
|
65
95
|
|
66
96
|
- `has_headers`: Boolean indicating if the first row contains headers (default: true)
|
67
97
|
- `col_sep`: String specifying the field separator (default: ",")
|
@@ -69,35 +99,13 @@ Both methods support the following options:
|
|
69
99
|
- `nil_string`: String that should be interpreted as nil
|
70
100
|
- by default, empty strings are interpreted as empty strings
|
71
101
|
- if you want to interpret empty strings as nil, set this to an empty string
|
72
|
-
- `buffer_size`: Integer specifying the
|
102
|
+
- `buffer_size`: Integer specifying the number of rows to buffer in memory (default: 1024)
|
73
103
|
- `result_type`: String specifying the output format ("hash" or "array" or :hash or :array)
|
74
104
|
- `flexible`: Boolean specifying if the parser should be flexible (default: false)
|
75
105
|
- `flexible_default`: String specifying the default value for missing fields. Implicitly enables flexible mode if set. (default: `nil`)
|
76
106
|
- `trim`: String specifying the trim mode ("all" or "headers" or "fields" or :all or :headers or :fields)
|
77
107
|
|
78
|
-
|
79
|
-
|
80
|
-
OSV supports reading from:
|
81
|
-
|
82
|
-
- File paths (as strings)
|
83
|
-
- IO objects
|
84
|
-
- Important caveat: the IO object must respond to `rb_io_descriptor` with a file descriptor.
|
85
|
-
- StringIO objects
|
86
|
-
- Note: when you do this, the string is read (in full) into a Rust string, and we parse it there.
|
87
|
-
|
88
|
-
```ruby
|
89
|
-
# From file path
|
90
|
-
OSV.for_each("path/to/file.csv") { |row| puts row["name"] }
|
91
|
-
|
92
|
-
# From IO object
|
93
|
-
File.open("path/to/file.csv") do |file|
|
94
|
-
OSV.for_each(file) { |row| puts row["name"] }
|
95
|
-
end
|
96
|
-
|
97
|
-
# From StringIO
|
98
|
-
data = StringIO.new("name,age\nJohn,25")
|
99
|
-
OSV.for_each(data) { |row| puts row["name"] }
|
100
|
-
```
|
108
|
+
When `has_headers` is false, hash keys will be generated as `"c0"`, `"c1"`, etc.
|
101
109
|
|
102
110
|
## Requirements
|
103
111
|
|
data/Rakefile
CHANGED
@@ -23,6 +23,7 @@ end
|
|
23
23
|
|
24
24
|
task :release do
|
25
25
|
sh "bundle exec rake test"
|
26
|
-
sh "
|
27
|
-
sh "gem
|
26
|
+
sh "mkdir -p pkg"
|
27
|
+
sh "gem build osv.gemspec -o pkg/osv-#{OSV::VERSION}.gem"
|
28
|
+
sh "gem push pkg/osv-#{OSV::VERSION}.gem"
|
28
29
|
end
|
data/lib/osv/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Jaremko
|
@@ -69,7 +69,7 @@ files:
|
|
69
69
|
- lib/osv/version.rb
|
70
70
|
homepage: https://github.com/njaremko/osv
|
71
71
|
licenses:
|
72
|
-
-
|
72
|
+
- MIT
|
73
73
|
metadata:
|
74
74
|
homepage_uri: https://github.com/njaremko/osv
|
75
75
|
source_code_uri: https://github.com/njaremko/osv
|