cbhpm_table 0.0.2 → 0.0.3

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: b6a10bb53622fd308b1fefaf6c6991bf211dc217
4
- data.tar.gz: 8a912754b3612394f42ff299e9003f9552d906e6
3
+ metadata.gz: e59d35c4b93ca98234df5edfee555894eaf654e8
4
+ data.tar.gz: f919dc7c957af39d58d866eac50e63c5ce24debc
5
5
  SHA512:
6
- metadata.gz: 1f54f0111fb5af87e3ff796cf54013ade0ff5b04355e4df5c9851afb006357fe9647e0a85219c804c527d8566b6203e61294d7b1b3b2a76cafd3fc62a9bbce69
7
- data.tar.gz: 4b90ffeedde779a03a1699dfc5b90a4afe762f6880004849d017af76455a5cff2850398198ea9b9949db01acd89b2db7bc9f1cb6236d3c27910e1429076ce46b
6
+ metadata.gz: f154fba675d6dc63186db8f9117c675995ed476c3ade823558676691864bb8b0f448682e8d411f8abea9978888599d3db199382ae9e2304c141c46ccdb0ce1ad
7
+ data.tar.gz: f217655a9ba0193e311aa877bb9267d215022e83f4845c1f5423c26adbcfdfb5f693f28433fea954532ea1c1f10edb908f99409a96c21d9a55d435c7e58443be
@@ -1,3 +1,3 @@
1
1
  class CBHPMTable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/cbhpm_table.rb CHANGED
@@ -3,17 +3,14 @@ require "cbhpm_table/version"
3
3
  require 'roo'
4
4
 
5
5
  class CBHPMTable
6
- attr_reader :roo, :headers_hash, :edition_name
6
+ attr_reader :roo
7
7
 
8
8
  def initialize(cbhpm_path, headers_hash = nil)
9
- cbhpm_file_extension = File.extname(cbhpm_path)
10
- cbhpm_file_basename = File.basename(cbhpm_path)
9
+ @cbhpm_path = cbhpm_path
11
10
 
12
- @edition_name = EDITION_NAME_FOR_FILE[cbhpm_file_basename]
13
-
14
- roo_class = ROO_CLASS_FOR_EXTENSION[cbhpm_file_extension]
11
+ roo_class = ROO_CLASS_FOR_EXTENSION[File.extname(cbhpm_path)]
15
12
  @roo = roo_class.new(cbhpm_path)
16
- @headers_hash = headers_hash || HEADER_FOR_FILE[cbhpm_file_basename]
13
+ @headers_hash = headers_hash || get_headers_hash
17
14
  raise "Can't find predefined headers for #{cbhpm_path}" unless @headers_hash
18
15
  end
19
16
 
@@ -43,6 +40,22 @@ class CBHPMTable
43
40
  each_row.to_a
44
41
  end
45
42
 
43
+ def edition_name
44
+ version_format[:edition_name]
45
+ end
46
+
47
+ def version_format
48
+ @version_format ||= get_version_format
49
+ end
50
+
51
+ def get_version_format
52
+ VERSION_FOR_FILE[File.basename(cbhpm_path)]
53
+ end
54
+
55
+ def cbhpm_path
56
+ @cbhpm_path
57
+ end
58
+
46
59
  def each_row
47
60
  return to_enum(:each_row) unless block_given?
48
61
  roo_enum = roo.to_enum(:each)
@@ -52,47 +65,77 @@ class CBHPMTable
52
65
  end
53
66
  end
54
67
 
55
- private :first_row_index, :import_row
68
+ def headers_hash
69
+ @headers_hash ||= get_headers_hash
70
+ end
71
+
72
+ def get_headers_hash
73
+ version_format[:header_format]
74
+ end
75
+
76
+ def start_date
77
+ version_format[:start_date]
78
+ end
79
+
80
+ def end_date
81
+ version_format[:end_date]
82
+ end
83
+
84
+ private :first_row_index, :import_row, :get_version_format, :get_headers_hash
56
85
  end
57
86
 
58
87
  class CBHPMTable
59
- module HeaderFormat
60
- CBHPM5a =
61
- { 0 => "code",
88
+ VERSIONS = {
89
+ :cbhpm5a => CBHPM5a = {
90
+ :file_basename => "CBHPM 5¶ Ediá∆o.xls",
91
+ :edition_name => "5a",
92
+ :header_format => {
93
+ 0 => "code",
62
94
  1 => "name",
63
95
  4 => "cir_size",
64
96
  5 => "uco",
65
97
  6 => "aux_qty",
66
- 7 => "an_size" }
67
-
68
- CBHPM2010 =
69
- { 0 => "code",
98
+ 7 => "an_size"
99
+ },
100
+ :start_date => "01/01/2008",
101
+ :end_date => "31/12/2009"
102
+ },
103
+ :cbhpm2010 => CBHPM2010 = {
104
+ :file_basename => "CBHPM 2010 separada.xls",
105
+ :edition_name => "2010",
106
+ :header_format => {
107
+ 0 => "code",
70
108
  1 => "name",
71
109
  4 => "cir_size",
72
110
  5 => "uco",
73
111
  6 => "aux_qty",
74
- 7 => "an_size" }
75
-
76
- CBHPM2012 =
77
- { 4 => "code",
112
+ 7 => "an_size"
113
+ },
114
+ :start_date => "01/01/2010",
115
+ :end_date => "31/12/2011"
116
+ },
117
+ :cbhpm2012 => CBHPM2012 = {
118
+ :file_basename => "CBHPM 2012.xlsx",
119
+ :edition_name => "2012",
120
+ :header_format => {
121
+ 4 => "code",
78
122
  5 => "name",
79
123
  8 => "cir_size",
80
124
  9 => "uco",
81
125
  10 => "aux_qty",
82
- 11 => "an_size" }
83
- end
84
-
85
- HEADER_FOR_FILE =
86
- { "CBHPM 5¶ Ediá∆o.xls" => HeaderFormat::CBHPM5a,
87
- "CBHPM 2010 separada.xls" => HeaderFormat::CBHPM2010,
88
- "CBHPM 2012.xlsx" => HeaderFormat::CBHPM2012,
89
- "cbhpm_cut_for_testing.xlsx" => HeaderFormat::CBHPM2012 }
90
-
91
- EDITION_NAME_FOR_FILE =
92
- { "CBHPM 5¶ Ediá∆o.xls" => "5a",
93
- "CBHPM 2010 separada.xls" => "2010",
94
- "CBHPM 2012.xlsx" => "2012",
95
- "cbhpm_cut_for_testing.xlsx" => "2012" }
126
+ 11 => "an_size"
127
+ },
128
+ :start_date => "01/01/2012",
129
+ :end_date => nil
130
+ }
131
+ }
132
+
133
+ VERSION_FOR_FILE = {
134
+ "CBHPM 5¶ Ediá∆o.xls" => CBHPM5a,
135
+ "CBHPM 2010 separada.xls" => CBHPM2010,
136
+ "CBHPM 2012.xlsx" => CBHPM2012,
137
+ "cbhpm_cut_for_testing.xlsx" => CBHPM2012
138
+ }
96
139
 
97
140
  ROO_CLASS_FOR_EXTENSION = { ".xls" => Roo::Excel, ".xlsx" => Roo::Excelx }
98
141
  end
@@ -4,13 +4,13 @@ require 'cbhpm_table'
4
4
  describe CBHPMTable do
5
5
  let(:cbhpm_table) do
6
6
  CBHPMTable.new("spec/cbhpm/cbhpm_cut_for_testing.xlsx",
7
- CBHPMTable::HeaderFormat::CBHPM2012)
7
+ CBHPMTable::CBHPM2012[:header_format])
8
8
  end
9
9
 
10
10
  it { expect(cbhpm_table).to respond_to(:headers) }
11
11
 
12
12
  describe "#headers_hash - the format hash for headers" do
13
- it { expect(cbhpm_table.headers_hash).to eq CBHPMTable::HeaderFormat::CBHPM2012 }
13
+ it { expect(cbhpm_table.headers_hash).to eq CBHPMTable::CBHPM2012[:header_format] }
14
14
  end
15
15
 
16
16
  describe "#headers - the first line of the CBHPM Table" do
@@ -63,5 +63,31 @@ describe CBHPMTable do
63
63
  describe "#edition_name" do
64
64
  it { expect(cbhpm_table.edition_name).to eq "2012" }
65
65
  end
66
+
67
+ describe "#version_format" do
68
+ it { expect(cbhpm_table.version_format).to be_instance_of Hash }
69
+ it "should return proper Hash with :edition_name key" do
70
+ STDOUT.puts cbhpm_table.version_format.inspect
71
+ expect(cbhpm_table.version_format[:edition_name]).to eq "2012"
72
+ end
73
+ end
74
+
75
+ describe "#cbhpm_path" do
76
+ it "should return the cbhpm initialization path" do
77
+ expect(cbhpm_table.cbhpm_path).to eq "spec/cbhpm/cbhpm_cut_for_testing.xlsx"
78
+ end
79
+ end
80
+
81
+ describe "#start_date" do
82
+ it "should return proper start_date for cbhpm version" do
83
+ expect(cbhpm_table.start_date).to eq "01/01/2012"
84
+ end
85
+ end
86
+
87
+ describe "#end_date" do
88
+ it "should return proper end_date for cbhpm version" do
89
+ expect(cbhpm_table.end_date).to eq nil
90
+ end
91
+ end
66
92
  end
67
93
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cbhpm_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abinoam Praxedes Marques Jr.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-28 00:00:00.000000000 Z
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler