takenoko 0.2.6 → 0.2.7

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: f9585a154baef8437a43f497bc18de665f1824fc
4
- data.tar.gz: 8dab39802e20d59c6e97177d6916bb21af10a58a
3
+ metadata.gz: 08ef0bb4b3b7c4482ec4470db97b30bb6fb85c35
4
+ data.tar.gz: 3483c0bbf4a6ed35fde43cda1a2b592042e657d0
5
5
  SHA512:
6
- metadata.gz: 3987057c1ee11165f6e757ddedc808f9764cfb2c3281320406a34a203414048af4e32368f511d94985853300c12666e35ba513841089b50a78aeb88f1cea1c1a
7
- data.tar.gz: 9cd9bb7943f4a9583229c8e8c8131c9c0917291cfa620c3217bf5b26613a0267749ae60b28519da8f2dbd92b613cc8b844c9da42408408d14c10ec71eb5a4cfd
6
+ metadata.gz: baaa50a24ac0d47750bdaf42e9e756d4d84cce59bf2418a812766146b3fdff57bd2f36ce781328f585e91a52badb85831c4a603c5d5cc1e321fb4a303ea5f0bc
7
+ data.tar.gz: 54a9d7da4fe0e43e3edf3de9ad359f2c300300e91db231f6923e1dd4ccc1d955ab17b6855e29b5dd75e0475a0d8d77a0b2e132ad36aabac390b7ed88f4ab4cfb
data/lib/takenoko.rb CHANGED
@@ -22,7 +22,7 @@ module Takenoko
22
22
 
23
23
  mattr_accessor :file_extension
24
24
  @@file_extension = :csv
25
- SUPPORTED_FILE_EXT = [:csv,:yaml,:json]
25
+ SUPPORTED_FILE_EXT = [:csv,:yaml,:json, :yml]
26
26
 
27
27
  mattr_accessor :export_file_location
28
28
  @@export_file_location = "db/spreadsheet"
@@ -41,9 +41,11 @@ module Takenoko
41
41
 
42
42
  [:yaml,:json].each do |output|
43
43
  define_method "convert_to_#{output}" do |table|
44
- table[:rows].public_send("to_#{output}")
44
+ table[:rows].map{|r| r.to_hash}.public_send("to_#{output}")
45
45
  end
46
46
  end
47
+
48
+ alias convert_to_yml convert_to_yaml
47
49
  end
48
50
 
49
51
  end
@@ -28,40 +28,38 @@ module Takenoko
28
28
  hash = HashWithIndifferentAccess.new
29
29
  table['columns_mapping'].each do |key,val|
30
30
  begin
31
- hash[key] = r.public_send(val)
31
+ val = r.public_send(val)
32
32
  rescue Exception => e
33
33
  if key == 'id'
34
- hash[key] = r.row_num - 1
34
+ val = r.row_num - 1
35
35
  else
36
- hash[key] = nil
36
+ val = nil
37
37
  end
38
38
  end
39
+ hash[key.to_sym] = format_row val
39
40
  end
40
41
  hash
41
- end.reject do |row|
42
- begin
43
- table[:enable_postprocess] && !postprocess_class.public_send("spreadsheet_row_valid?",row)
44
- rescue NoMethodError => e
45
- Rails.logger.warn e.message
46
- false
47
- end
48
- end.map do |row|
49
- begin
50
- table[:enable_postprocess] ? postprocess_class.public_send("postprocess_spreadsheet_row",row) : row
51
- rescue NoMethodError => e
52
- Rails.logger.warn e.message
53
- row
54
- end
55
42
  end
56
43
 
57
- table[:rows] = rows
58
- if table[:enable_postprocess]
59
- begin
60
- table = postprocess_class.public_send("postprocess_spreadsheet_table",table)
61
- rescue NoMethodError => e
62
- Rails.logger.warn e.message
44
+ if(table[:enable_postprocess])
45
+ rows.reject do |row|
46
+ if postprocess_class.respond_to? "spreadsheet_row_valid?"
47
+ postprocess_class.public_send("spreadsheet_row_valid?",row)
48
+ end
49
+ end.map do |row|
50
+ if postprocess_class.respond_to? "postprocess_spreadsheet_row"
51
+ row = postprocess_class.public_send("postprocess_spreadsheet_row",row)
52
+ end
63
53
  end
54
+
55
+ table[:rows] = rows
56
+ if postprocess_class.respond_to? "postprocess_spreadsheet_table"
57
+ table = postprocess_class.public_send("postprocess_spreadsheet_table",table)
58
+ end
59
+ else
60
+ table[:rows] = rows
64
61
  end
62
+
65
63
  return table
66
64
  end
67
65
 
@@ -119,5 +117,10 @@ module Takenoko
119
117
  table[:header] = table[:columns_mapping].keys
120
118
  return table
121
119
  end
120
+
121
+ def format_row(v)
122
+ return nil unless v
123
+ ((float = Float(v)) && (float % 1.0 == 0) ? float.to_i : float) rescue v
124
+ end
122
125
  end
123
126
  end
@@ -1,3 +1,3 @@
1
1
  module Takenoko
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: takenoko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - KhiemNS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-25 00:00:00.000000000 Z
11
+ date: 2016-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -89,7 +89,7 @@ files:
89
89
  - lib/tasks/takenoko.rake
90
90
  - test/takenoko_test.rb
91
91
  - test/test_helper.rb
92
- homepage: https://github.com/khiemns54/takenoko/tree/release/0.2.6
92
+ homepage: https://github.com/khiemns54/takenoko/tree/release/0.2.7
93
93
  licenses: []
94
94
  metadata: {}
95
95
  post_install_message: