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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf22f4626ef0b7c1a99f0e1342ea118deca30cf3
4
- data.tar.gz: 00e0bc67b4dddcd8498ab799f6f4cea54860e610
3
+ metadata.gz: 04eb0ee9da1f7740a2baedb915e884737b6573b7
4
+ data.tar.gz: 0fe6f0170090a1b13597c1619d4d7311904fdbaa
5
5
  SHA512:
6
- metadata.gz: f6704f9b8a63421586c40c9f8bb8252dc182e57e8078b03589f5217e9c364872388ba1b57c1ad4ff2fc8ac3ce086ca98486003cb80c0497cbf24bb60395094ae
7
- data.tar.gz: 111fdcbded392511da6ad88f459a5fd5347191ee05a2de360d53c694347e84a3938608ee792e5f77e5d1ecc4b78c48ba13a50b189b4c258561ce3a25c313c912
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 parseCSV files.
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
- { first_name: 'Luke', last_name: 'Skywalker' },
47
- { first_name: 'Han', last_name: 'Solo' }
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SeparatedValues
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: separated_values
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emric