fruit_to_lime 0.6.3 → 0.6.4
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.
data/lib/fruit_to_lime.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "csv"
|
2
|
+
module FruitToLime
|
3
|
+
class RooHelper
|
4
|
+
def initialize(data)
|
5
|
+
@data = data
|
6
|
+
@sheet = data.sheets.first
|
7
|
+
@map = {}
|
8
|
+
1.upto(data.last_column(@sheet)) do |col|
|
9
|
+
@map[col] = @data.cell(1, col, @sheet).encode('UTF-8')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def rows
|
14
|
+
rs = []
|
15
|
+
2.upto(@data.last_row(@sheet)) do |row|
|
16
|
+
r={}
|
17
|
+
1.upto(@data.last_column(@sheet)) do |col|
|
18
|
+
val = cell_to_csv(row, col, @sheet)
|
19
|
+
r[@map[col]] = val
|
20
|
+
end
|
21
|
+
rs.push(r)
|
22
|
+
end
|
23
|
+
return rs
|
24
|
+
end
|
25
|
+
|
26
|
+
def cell_to_csv(row, col, sheet)
|
27
|
+
if @data.empty?(row,col,sheet)
|
28
|
+
''
|
29
|
+
else
|
30
|
+
onecell = @data.cell(row,col,sheet)
|
31
|
+
case @data.celltype(row,col,sheet)
|
32
|
+
when :string
|
33
|
+
unless onecell.empty?
|
34
|
+
onecell.encode('UTF-8')
|
35
|
+
end
|
36
|
+
when :float, :percentage
|
37
|
+
if onecell == onecell.to_i
|
38
|
+
onecell.to_i.to_s
|
39
|
+
else
|
40
|
+
onecell.to_s
|
41
|
+
end
|
42
|
+
when :date, :datetime
|
43
|
+
onecell.to_s
|
44
|
+
when :time
|
45
|
+
Roo::Base.integer_to_timestring(onecell)
|
46
|
+
else
|
47
|
+
raise "unhandled celltype #{@data.celltype(row,col,sheet)}"
|
48
|
+
end || ""
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module FruitToLime
|
2
2
|
module SerializeHelper
|
3
3
|
|
4
|
-
def fill_using(entity_columns, row)
|
4
|
+
def fill_using(entity_columns, row)# TODO: Move to InCSV
|
5
5
|
entity_columns.select do |ecol|
|
6
6
|
ecol.selected!=nil && ecol.selected.length >0 && ecol.column!=nil && ecol.column.length > 0
|
7
7
|
end.each do |ecol|
|
@@ -57,7 +57,7 @@ module SerializeHelper
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
def set_attribute(selected, value)
|
60
|
+
def set_attribute(selected, value)# TODO: Move to InCSV
|
61
61
|
if selected.is_a? String
|
62
62
|
selected = [selected]
|
63
63
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fruit_to_lime'
|
3
|
+
require 'roo'
|
4
|
+
describe FruitToLime::RooHelper do
|
5
|
+
it "should handle sv chars" do
|
6
|
+
samplefile = File.join(File.dirname(__FILE__), '..', 'sample_data', 'excel.xlsx')
|
7
|
+
rows = FruitToLime::RooHelper.new(Roo::Excelx.new(samplefile)).rows
|
8
|
+
rows.should include({"Alpha"=>"L\u00E5s","Beta"=>"m\u00E4sk","\u00D6rjan"=>"l\u00E4sk","\u00C4skil"=>""})
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fruit_to_lime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-10-
|
13
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: iso_country_codes
|
@@ -81,11 +81,13 @@ files:
|
|
81
81
|
- lib/fruit_to_lime/model/rootmodel.rb
|
82
82
|
- lib/fruit_to_lime/model/sourceref.rb
|
83
83
|
- lib/fruit_to_lime/model/tag.rb
|
84
|
+
- lib/fruit_to_lime/roo_helper.rb
|
84
85
|
- lib/fruit_to_lime/serialize_helper.rb
|
85
86
|
- lib/fruit_to_lime.rb
|
86
87
|
- spec/gosourceref_spec.rb
|
87
88
|
- spec/helpers/address_helper_spec.rb
|
88
89
|
- spec/helpers/csv_helper_spec.rb
|
90
|
+
- spec/helpers/roo_helper_spec.rb
|
89
91
|
- spec/helpers/serialize_helper_spec.rb
|
90
92
|
- spec/person_spec.rb
|
91
93
|
- spec/spec_helper.rb
|
@@ -117,6 +119,7 @@ test_files:
|
|
117
119
|
- spec/gosourceref_spec.rb
|
118
120
|
- spec/helpers/address_helper_spec.rb
|
119
121
|
- spec/helpers/csv_helper_spec.rb
|
122
|
+
- spec/helpers/roo_helper_spec.rb
|
120
123
|
- spec/helpers/serialize_helper_spec.rb
|
121
124
|
- spec/person_spec.rb
|
122
125
|
- spec/spec_helper.rb
|