multidimensional_table 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  require 'multidimensional_table/non_existant_dimension_attribute'
2
- require 'multidimensional_table/non_valid_dimension'
2
+ require 'multidimensional_table/more_than_one_result'
3
3
 
4
4
  module MultidimensionalTable
5
5
 
@@ -10,7 +10,6 @@ module MultidimensionalTable
10
10
 
11
11
  def set_dimensions(map)
12
12
  @dimensions = map
13
- check_duplicates(map)
14
13
  @dimensions.each do |key, value|
15
14
  value.each do |possible_value|
16
15
  Kernel.class_eval do
@@ -34,35 +33,16 @@ module MultidimensionalTable
34
33
  end
35
34
  end
36
35
 
37
- def check_duplicates(map)
38
- list = {}
39
- combined = map.each_value.reduce([]) { |all, value| all << value }.flatten
40
- combined.each do |item|
41
- if list[item].nil?
42
- list[item] = 1
43
- else
44
- list[item] = list[item] + 1
45
- end
46
- end
47
- duplicates = list.select { |key, value| key if value > 1 }
48
- if duplicates != {}
49
- non_valid_dimensions = {}
50
- duplicates.each_key do |duplicate|
51
- non_valid_dimensions[duplicate] = []
52
- map.each do |key,value|
53
- non_valid_dimensions[duplicate] << key if value.include?(duplicate)
54
- end
55
- end
56
- raise NonValidDimension, non_valid_dimensions
57
- end
58
- end
59
-
60
36
  def update_attributes(attrs)
61
37
  attrs.each do |key, value| @attributes[key] = value end
62
38
  end
63
39
 
64
40
  def table_result
65
- @table_rules.each { |key, condition| return key if eval(condition.join(' && ')) == true }
41
+ result = @table_rules.each { |key, condition| return key if eval(condition.join(' && ')) == true }
42
+ if result.size > 1
43
+ raise MoreThanOneResult, result
44
+ end
45
+ result
66
46
  end
67
47
 
68
48
  def table_data
@@ -1,3 +1,3 @@
1
1
  module MultidimensionalTable
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -117,13 +117,25 @@ module MultidimensionalTable
117
117
  end.to raise_error(NonExistantDimensionAttribute, 'Nonexistan dimension attribute :coal_error')
118
118
  end
119
119
 
120
- it 'should complain if same dimension name exists' do
120
+ it 'should complain when there are multiple results' do
121
121
  subject.extend(MultidimensionalTable)
122
+ subject.set_dimensions( { :material => [:potassium, :coal, :sugar],
123
+ :city => [:zagreb, :zadar],
124
+ :time_of_day => [:morning, :evening] })
125
+
126
+ subject.table_data do
127
+ subject.zagreb do
128
+ subject.morning do
129
+ subject.coal '8t'
130
+ subject.sugar '9t'
131
+ end
132
+ end
133
+ end
134
+ subject.update_attributes(:material => :coal, :city => :zagreb, :time_of_day => :evening)
135
+
122
136
  expect do
123
- subject.set_dimensions ({ :material => [:potassium, :coal, :sugar],
124
- :city => [:zagreb, :zadar],
125
- :time_of_day => [:coal, :zagreb] })
126
- end.to raise_error(NonValidDimension, 'Multiple definitions are not allowed : coal for dimension material and time_of_day, zagreb for dimension city and time_of_day')
137
+ subject.table_result.should == '8t'
138
+ end.to raise_error(MoreThanOneResult, 'More than one result :8t, 9t')
127
139
  end
128
140
 
129
141
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multidimensional_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-25 00:00:00.000000000Z
12
+ date: 2012-03-26 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Describe a multidimensional table in pure Ruby
15
15
  email:
@@ -27,7 +27,6 @@ files:
27
27
  - lib/multidimensional_table.rb
28
28
  - lib/multidimensional_table/multidimensional_table.rb
29
29
  - lib/multidimensional_table/non_existant_dimension_attribute.rb
30
- - lib/multidimensional_table/non_valid_dimension.rb
31
30
  - lib/multidimensional_table/test_class.rb
32
31
  - lib/multidimensional_table/version.rb
33
32
  - multidimensional_table.gemspec
@@ -1,18 +0,0 @@
1
- module MultidimensionalTable
2
- class NonValidDimension < StandardError
3
- attr_accessor :duplicate
4
- def initialize(duplicate)
5
- @duplicate = duplicate
6
- end
7
-
8
- def to_s
9
- "Multiple definitions are not allowed : #{represent_duplicates}"
10
- end
11
-
12
- def represent_duplicates
13
- duplicate.map do |key, value|
14
- "#{key} for dimension " << value.join(' and ')
15
- end.join(', ')
16
- end
17
- end
18
- end