csv_coordinate_accessor 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/csv_coordinate_accessor.rb +7 -4
- data/lib/csv_coordinate_accessor/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: 7d5d6a17de06c8826dc99210ba8cea99466cbc9f
|
4
|
+
data.tar.gz: 2f7f0802ba80628defc42d86e915925b1aa75f0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05bb8701420b222f7a72d3a4bbba90ef97782ff191e42ce302f072e30e8e518580454128e0d86beb3166160c11289594814861cca1504440a14735ebaa971a6e
|
7
|
+
data.tar.gz: b12bd4dde3f35d686abbad6c4c50860f8e16672b12dab19882ef6a1fdf2f6d2574189b10367c831ce2115f8691f71dd0c301f3c3967cdb648832ce26a503bac8
|
data/README.md
CHANGED
@@ -29,15 +29,15 @@ csv = CSV.read('./spec/fixtures/sample.csv').extend CSVCoordinateAccessor
|
|
29
29
|
csv = csv.extend CSVCoordinateAccessor
|
30
30
|
|
31
31
|
## get value with coordinate
|
32
|
-
csv.get('
|
32
|
+
csv.get('A2')
|
33
33
|
=> "1"
|
34
|
-
csv.get('
|
34
|
+
csv.get('B2')
|
35
35
|
=> "fruit"
|
36
|
-
csv.get('
|
36
|
+
csv.get('C2')
|
37
37
|
=> "apple"
|
38
38
|
|
39
39
|
## set value with coordinate
|
40
|
-
csv.set('
|
40
|
+
csv.set('C2', 'pineapple')
|
41
41
|
|
42
42
|
csv
|
43
43
|
=> [["id", "category", "name"], ["1", "fruit", "pineapple"], ["2", "furit", "orange"], ["3", "fruit", "banana"]]
|
@@ -17,10 +17,13 @@ module CSVCoordinateAccessor
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def cord2index(cord)
|
20
|
-
m = cord.match(/(
|
20
|
+
m = cord.match(/(?<codes>[A-Za-z]+)(?<nums>\d+)/) \
|
21
|
+
|| cord.match(/(?<nums>\d+)(?<codes>[A-Za-z]+)/)
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
raise ArgumentError, "#{cord} is invalid" unless m
|
24
|
+
|
25
|
+
r = m['nums'].to_i - 1
|
26
|
+
c = code2index(m['codes'])
|
24
27
|
[r, c]
|
25
28
|
end
|
26
29
|
|
@@ -41,7 +44,7 @@ module CSVCoordinateAccessor
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def code2index(code)
|
44
|
-
chars = code.split('')
|
47
|
+
chars = code.upcase.split('')
|
45
48
|
num = 0
|
46
49
|
chars.each.with_index do |c, i|
|
47
50
|
n = c.ord - CODES.first.ord
|