height 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe Height::Units::Base do
4
+
5
+ describe '#to_unit' do
6
+ it 'converts unit into another unit' do
7
+ @centimeters = Height::Units::Centimeters.new(41)
8
+
9
+ @centimeters.to_unit(Height::Units::Meters).should == Height::Units::Meters.new(0.41)
10
+ end
11
+ end
12
+
13
+ describe '==' do
14
+ it { Height::Units::Meters.new(1.5).should == Height::Units::Centimeters.new(150) }
15
+ it { Height::Units::Centimeters.new(127).should == Height::Units::Inches.new(50) }
16
+ it { Height::Units::Feet.new(6).should == Height::Units::Centimeters.new(183) }
17
+ end
18
+
19
+ describe '+' do
20
+ before do
21
+ @meters = Height::Units::Meters.new(1.5)
22
+ @centimeters = Height::Units::Centimeters.new(41)
23
+ end
24
+
25
+ it 'adds other unit' do
26
+ (@meters + @centimeters).should == Height::Units::Meters.new(1.91)
27
+ end
28
+
29
+ it 'adds numeric object' do
30
+ (@meters + 0.5).should == Height::Units::Meters.new(2)
31
+ end
32
+
33
+ it 'returns instance of the class of the first unit' do
34
+ (@meters + @centimeters).class.should == Height::Units::Meters
35
+ end
36
+ end
37
+
38
+ describe '-' do
39
+ before do
40
+ @feet = Height::Units::Feet.new(6.25)
41
+ @inches = Height::Units::Inches.new(3)
42
+ end
43
+
44
+ it 'substracts other unit' do
45
+ (@feet - @inches).should == Height::Units::Feet.new(6)
46
+ end
47
+
48
+ it 'substracts numeric objects' do
49
+ (@feet - 0.25).should == Height::Units::Feet.new(6)
50
+ end
51
+
52
+ it 'returns instance of the class of the first unit' do
53
+ (@feet + @inches).class.should == Height::Units::Feet
54
+ end
55
+ end
56
+
57
+ describe '*' do
58
+ before do
59
+ @meters = Height::Units::Meters.new(2)
60
+ @centimeters = Height::Units::Centimeters.new(200)
61
+ end
62
+
63
+ it 'multiplies by other unit' do
64
+ (@meters * @centimeters).should == Height::Units::Meters.new(4)
65
+ end
66
+
67
+ it 'multiplies by numeric object' do
68
+ (@meters * 2).should == Height::Units::Meters.new(4)
69
+ end
70
+
71
+ it 'returns instance of the class of the first unit' do
72
+ (@meters * @centimeters).class.should == Height::Units::Meters
73
+ end
74
+ end
75
+
76
+ describe '/' do
77
+ before do
78
+ @meters = Height::Units::Meters.new(2)
79
+ @centimeters = Height::Units::Centimeters.new(200)
80
+ end
81
+
82
+ it 'divides by other unit' do
83
+ (@meters / @centimeters).should == Height::Units::Meters.new(1)
84
+ end
85
+
86
+ it 'divides by numeric object' do
87
+ (@meters / 2).should == Height::Units::Meters.new(1)
88
+ end
89
+
90
+ it 'returns instance of the class of the first unit' do
91
+ (@meters / @centimeters).class.should == Height::Units::Meters
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Height::Units::Centimeters do
4
+
5
+ describe 'converts to' do
6
+ before do
7
+ @centimeters = Height::Units::Centimeters.new(191)
8
+ end
9
+
10
+ it 'centimeters' do
11
+ @centimeters.to_centimeters.should === @centimeters
12
+ end
13
+
14
+ it 'meters' do
15
+ @centimeters.to_meters.should == Height::Units::Meters.new(1.91)
16
+ end
17
+
18
+ it 'inches' do
19
+ @centimeters.to_inches.should == Height::Units::Inches.new(75)
20
+ end
21
+
22
+ it 'feet' do
23
+ @centimeters.to_feet.should == Height::Units::Feet.new(6.25)
24
+ end
25
+
26
+ it 'string' do
27
+ Height::Units::Centimeters.new(191.0).to_s.should == '191'
28
+ end
29
+ end
30
+
31
+ it 'rounds the value to 0 digit precision' do
32
+ Height::Units::Centimeters.new(191.51).value.should == 192
33
+ end
34
+
35
+ end
36
+
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Height::Units::Feet do
4
+
5
+ describe 'converts to' do
6
+ before do
7
+ @feet = Height::Units::Feet.new(6.25)
8
+ end
9
+
10
+ it 'feet' do
11
+ @feet.to_feet.should === @feet
12
+ end
13
+
14
+ it 'inches' do
15
+ @feet.to_inches.should == Height::Units::Inches.new(75)
16
+ end
17
+
18
+ it 'centimeters' do
19
+ @feet.to_centimeters.should == Height::Units::Centimeters.new(190.5)
20
+ end
21
+
22
+ it 'meters' do
23
+ @feet.to_meters.should == Height::Units::Meters.new(1.91)
24
+ end
25
+
26
+ it 'string' do
27
+ Height::Units::Feet.new(6.25).to_s.should == '6.25'
28
+ Height::Units::Feet.new(6.0).to_s.should == '6'
29
+ end
30
+ end
31
+
32
+ it 'has feet' do
33
+ Height::Units::Feet.new(6.25).feet.should == Height::Units::Feet.new(6)
34
+ Height::Units::Feet.new(6.75).feet.should == Height::Units::Feet.new(6)
35
+ end
36
+
37
+ it 'has inches' do
38
+ Height::Units::Feet.new(6.25).inches.should == Height::Units::Inches.new(3)
39
+ end
40
+
41
+ it 'rounds the value to 2 digit precision' do
42
+ Height::Units::Feet.new(6.251).value.should == 6.25
43
+ end
44
+ end
45
+
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Height::Units::Inches do
4
+
5
+ describe 'converts to' do
6
+ before do
7
+ @inches = Height::Units::Inches.new(75)
8
+ end
9
+
10
+ it 'inches' do
11
+ @inches.to_inches.should === @inches
12
+ end
13
+
14
+ it 'feet' do
15
+ @inches.to_feet.should == Height::Units::Feet.new(6.25)
16
+ end
17
+
18
+ it 'centimeters' do
19
+ @inches.to_centimeters.should == Height::Units::Centimeters.new(190.5)
20
+ end
21
+
22
+ it 'meters' do
23
+ @inches.to_meters.should == Height::Units::Meters.new(1.91)
24
+ end
25
+
26
+ it 'string' do
27
+ Height::Units::Inches.new(75.0).to_s.should == '75'
28
+ Height::Units::Inches.new(72.4).to_s.should == '72'
29
+ end
30
+ end
31
+
32
+ it 'rounds the value to 0 digit precision' do
33
+ Height::Units::Inches.new(72.4).value.should == 72
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Height::Units::Meters do
4
+
5
+ describe 'converts to' do
6
+ before do
7
+ @meters = Height::Units::Meters.new(1.91)
8
+ end
9
+
10
+ it 'meters' do
11
+ @meters.to_meters.should === @meters
12
+ end
13
+
14
+ it 'centimeters' do
15
+ @meters.to_centimeters.should == Height::Units::Centimeters.new(191)
16
+ end
17
+
18
+ it 'inches' do
19
+ @meters.to_inches.should == Height::Units::Inches.new(75.2)
20
+ end
21
+
22
+ it 'feet' do
23
+ @meters.to_feet.should == Height::Units::Feet.new(6.25)
24
+ end
25
+
26
+ it 'string' do
27
+ Height::Units::Meters.new(1.914).to_s.should == '1.91'
28
+ Height::Units::Meters.new(2.0).to_s.should == '2'
29
+ end
30
+ end
31
+
32
+ it 'has meters' do
33
+ Height::Units::Meters.new(1.91).meters.should == Height::Units::Meters.new(1)
34
+ Height::Units::Meters.new(1.41).meters.should == Height::Units::Meters.new(1)
35
+ end
36
+
37
+ it 'has centimeters' do
38
+ Height::Units::Meters.new(1.91).centimeters.should == Height::Units::Centimeters.new(91)
39
+ end
40
+
41
+ it 'rounds the value to 2 digit precision' do
42
+ Height::Units::Meters.new(1.914).value.should == 1.91
43
+ end
44
+ end
45
+
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Height::Units::Millimeters do
4
+
5
+ describe 'converts to' do
6
+ before do
7
+ @millimeters = Height::Units::Millimeters.new(1910)
8
+ end
9
+
10
+ it 'millimeters' do
11
+ @millimeters.to_millimeters.should === @millimeters
12
+ end
13
+
14
+ it 'centimeters' do
15
+ @millimeters.to_centimeters.should == Height::Units::Centimeters.new(191)
16
+ end
17
+
18
+ it 'meters' do
19
+ @millimeters.to_meters.should == Height::Units::Meters.new(1.91)
20
+ end
21
+
22
+ it 'inches' do
23
+ @millimeters.to_inches.should == Height::Units::Inches.new(75)
24
+ end
25
+
26
+ it 'feet' do
27
+ @millimeters.to_feet.should == Height::Units::Feet.new(6.25)
28
+ end
29
+
30
+ it 'string' do
31
+ Height::Units::Millimeters.new(1.6).to_s.should == '2'
32
+ Height::Units::Millimeters.new(1.0).to_s.should == '1'
33
+ end
34
+ end
35
+
36
+ it 'rounds the value to 0 digit precision' do
37
+ Height::Units::Millimeters.new(1914.5).value.should == 1915
38
+ end
39
+
40
+ end
41
+
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: height
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Zaytsev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: i18n
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Height support for metric and imperial systems
79
+ email:
80
+ - alexander@say26.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - Gemfile
88
+ - LICENSE
89
+ - README.md
90
+ - Rakefile
91
+ - height.gemspec
92
+ - lib/height.rb
93
+ - lib/height/core_extensions.rb
94
+ - lib/height/formatters/base.rb
95
+ - lib/height/formatters/imperial.rb
96
+ - lib/height/formatters/metric.rb
97
+ - lib/height/parser.rb
98
+ - lib/height/parsers/base.rb
99
+ - lib/height/parsers/imperial.rb
100
+ - lib/height/parsers/metric.rb
101
+ - lib/height/units/base.rb
102
+ - lib/height/units/centimeters.rb
103
+ - lib/height/units/feet.rb
104
+ - lib/height/units/inches.rb
105
+ - lib/height/units/meters.rb
106
+ - lib/height/units/millimeters.rb
107
+ - lib/height/version.rb
108
+ - spec/core_extensions_spec.rb
109
+ - spec/formatters/imperial_spec.rb
110
+ - spec/formatters/metric_spec.rb
111
+ - spec/height_spec.rb
112
+ - spec/parser_spec.rb
113
+ - spec/parsers/imperial_spec.rb
114
+ - spec/parsers/metric_spec.rb
115
+ - spec/spec_helper.rb
116
+ - spec/units/base_spec.rb
117
+ - spec/units/centimeters_spec.rb
118
+ - spec/units/feet_spec.rb
119
+ - spec/units/inches_spec.rb
120
+ - spec/units/meters_spec.rb
121
+ - spec/units/millimeters_spec.rb
122
+ homepage: http://github.com/AlexanderZaytsev/height
123
+ licenses: []
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ segments:
135
+ - 0
136
+ hash: 4172231473958665571
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ segments:
144
+ - 0
145
+ hash: 4172231473958665571
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 1.8.24
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: Convert height between metric and imperial systems
152
+ test_files:
153
+ - spec/core_extensions_spec.rb
154
+ - spec/formatters/imperial_spec.rb
155
+ - spec/formatters/metric_spec.rb
156
+ - spec/height_spec.rb
157
+ - spec/parser_spec.rb
158
+ - spec/parsers/imperial_spec.rb
159
+ - spec/parsers/metric_spec.rb
160
+ - spec/spec_helper.rb
161
+ - spec/units/base_spec.rb
162
+ - spec/units/centimeters_spec.rb
163
+ - spec/units/feet_spec.rb
164
+ - spec/units/inches_spec.rb
165
+ - spec/units/meters_spec.rb
166
+ - spec/units/millimeters_spec.rb