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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0709b7b796eae7601320c8af4ade1382b6c88591
4
- data.tar.gz: 01d7ef5e5563440d217ad64c493f55b9c974e66d
3
+ metadata.gz: 7d5d6a17de06c8826dc99210ba8cea99466cbc9f
4
+ data.tar.gz: 2f7f0802ba80628defc42d86e915925b1aa75f0c
5
5
  SHA512:
6
- metadata.gz: b5c6cc47d695072ab91387e358549356fbb64f31e71845fa105c6d974d2a7a42a08fe4935f32290c52ead6be31ff232324a698850322af91331fc790dcb4e92a
7
- data.tar.gz: f668cc5816251ef929d8c91bec7ec8a0fa1dfb9f0556d3ea88b37a749fd62aa919ac7b2daa301bd64e1b98f2087fba3a80f3cda7804b33608f42a188ab484401
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('2A')
32
+ csv.get('A2')
33
33
  => "1"
34
- csv.get('2B')
34
+ csv.get('B2')
35
35
  => "fruit"
36
- csv.get('2C')
36
+ csv.get('C2')
37
37
  => "apple"
38
38
 
39
39
  ## set value with coordinate
40
- csv.set('2C', 'pineapple')
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(/(\d+)(\w+)/)
20
+ m = cord.match(/(?<codes>[A-Za-z]+)(?<nums>\d+)/) \
21
+ || cord.match(/(?<nums>\d+)(?<codes>[A-Za-z]+)/)
21
22
 
22
- r = m[1].to_i - 1
23
- c = code2index(m[2])
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
@@ -1,3 +1,3 @@
1
1
  module CSVCoordinateAccessor
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_coordinate_accessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keisuke Ishizawa