separated_values 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -5
- data/lib/separated_values/row.rb +9 -0
- data/lib/separated_values/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04eb0ee9da1f7740a2baedb915e884737b6573b7
|
4
|
+
data.tar.gz: 0fe6f0170090a1b13597c1619d4d7311904fdbaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 132d888e696f98d9ffc294a363df7bda19ea89ec431a86360b9e8fa0c7125014eb9ed791be06bd394047dd36022bf62a01636f2ff5c992c535971276e527e38c
|
7
|
+
data.tar.gz: 6cfd36efb7f228b2a906d12bfcdbbecbace7bfde417a03cb7bd70ce272ed1c9acd1cc1fe29ae500fdbcf28b619181591ba75a747d927e06d24ecd92470a48345
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ of the file. You can access the cell values as a two dimensional array.
|
|
32
32
|
document[0][0] = 'foo'
|
33
33
|
```
|
34
34
|
|
35
|
-
The parser will default to
|
35
|
+
The parser will default to parse CSV files.
|
36
36
|
If you want to parse a custom format you can use the `:separator` option.
|
37
37
|
```ruby
|
38
38
|
document = SeparatedValues.parse('my_file.tsv', separator: '\t')
|
@@ -42,10 +42,18 @@ The parser also comes with the handy `:schema` option.
|
|
42
42
|
By providing this option you can convert the document to an array of hashes:
|
43
43
|
```ruby
|
44
44
|
document = SeparatedValues.parse('my_file.csv', schema: [:first_name, :last_name])
|
45
|
-
document.to_hash_array
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
document.to_hash_array
|
46
|
+
#=>
|
47
|
+
# [
|
48
|
+
# { first_name: 'Luke', last_name: 'Skywalker' },
|
49
|
+
# { first_name: 'Han', last_name: 'Solo' }
|
50
|
+
# ]
|
51
|
+
```
|
52
|
+
|
53
|
+
The keys defined in the schema will also be available as methods:
|
54
|
+
```ruby
|
55
|
+
document = SeparatedValues.parse('my_file.csv', schema: [:first_name, :last_name])
|
56
|
+
document[0].first_name = 'Luke'
|
49
57
|
```
|
50
58
|
|
51
59
|
## Development
|
data/lib/separated_values/row.rb
CHANGED
@@ -16,5 +16,14 @@ module SeparatedValues
|
|
16
16
|
hash[key] = @values[i]
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
def method_missing(name, *args, &block)
|
21
|
+
return to_h[name] if respond_to_missing?(name, *args)
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def respond_to_missing?(name, *args)
|
26
|
+
!!options[:schema] && options[:schema].include?(name)
|
27
|
+
end
|
19
28
|
end
|
20
29
|
end
|