joules 0.3.1 → 0.3.2

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/joules/waves.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing waves formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.3.1 01/06/2015
6
+ # @version: 0.3.2 03/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Waves module (waves.rb)
@@ -15,9 +15,9 @@ module Joules
15
15
  # @param frequency [Int, Float]
16
16
  # frequency > 0; frequency is in hertz
17
17
  # @param wavelength [Int, Float]
18
- # wavelength >= 0; wavelength is in meters
18
+ # wavelength >= 0; wavelength is in metres
19
19
  # @return [Float]
20
- # return value >= 0; return value is in meters per second
20
+ # return value >= 0; return value is in metres per second
21
21
  # @example
22
22
  # Joules.wave_speed(3250, 0.1) #=> 325.0
23
23
  def wave_speed(frequency, wavelength)
@@ -26,29 +26,39 @@ module Joules
26
26
 
27
27
  # Calculates the wavelength given wave speed and frequency.
28
28
  # @param wave_speed [Int, Float]
29
- # wave_speed >= 0; wave_speed is in meters per second
29
+ # wave_speed >= 0; wave_speed is in metres per second
30
30
  # @param frequency [Int, Float]
31
31
  # frequency > 0; frequency is in hertz
32
32
  # @return [Float]
33
- # return value is in meters
33
+ # return value is in metres
34
+ # @raise [ZeroDivisionError] if frequency = 0
34
35
  # @example
35
36
  # Joules.wavelength(325, 3250) #=> 0.1
36
37
  def wavelength(wave_speed, frequency)
37
- return wave_speed / frequency.to_f
38
+ if frequency.zero?
39
+ raise ZeroDivisionError.new('divided by 0')
40
+ else
41
+ return wave_speed / frequency.to_f
42
+ end
38
43
  end
39
44
 
40
45
  # Calculates the frequency given wave speed and wavelength.
41
46
  # @param wave_speed [Int, Float]
42
- # wave_speed >= 0; wave_speed is in meters per second
47
+ # wave_speed >= 0; wave_speed is in metres per second
43
48
  # @param wavelength [Int, Float]
44
- # wavelength > 0; wavelength is in meters
49
+ # wavelength > 0; wavelength is in metres
45
50
  # @return [Float]
46
51
  # return value is in hertz
52
+ # @raise [ZeroDivisionError] if wavelength = 0
47
53
  # @example
48
54
  # Joules.frequency_v1(325, 0.1) #=> 3250.0
49
55
  # @note There is one other method for calculating frequency.
50
56
  def frequency_v1(wave_speed, wavelength)
51
- return wave_speed / wavelength.to_f
57
+ if wavelength.zero?
58
+ raise ZeroDivisionError.new('divided by 0')
59
+ else
60
+ return wave_speed / wavelength.to_f
61
+ end
52
62
  end
53
63
 
54
64
  # Calculates the frequency given time period.
@@ -56,11 +66,16 @@ module Joules
56
66
  # time_period > 0; time_period is in seconds
57
67
  # @return [Float]
58
68
  # return value > 0; return value is in hertz
69
+ # @raise [ZeroDivisionError] if time_period = 0
59
70
  # @example
60
71
  # Joules.frequency_v2(12.5) #=> 0.08
61
72
  # @note There is one other method for calculating frequency.
62
73
  def frequency_v2(time_period)
63
- return 1.0 / time_period
74
+ if time_period.zero?
75
+ raise ZeroDivisionError.new('divided by 0')
76
+ else
77
+ return 1.0 / time_period
78
+ end
64
79
  end
65
80
 
66
81
  # Calculates the time period given frequency.
@@ -68,35 +83,50 @@ module Joules
68
83
  # frequency > 0; frequency is in hertz
69
84
  # @return [Float]
70
85
  # return value > 0; return value is in hertz
86
+ # @raise [ZeroDivisionError] if frequency = 0
71
87
  # @example
72
88
  # Joules.time_period(0.08) #=> 12.5
73
89
  def time_period(frequency)
74
- return 1.0 / frequency
90
+ if frequency.zero?
91
+ raise ZeroDivisionError.new('divided by 0')
92
+ else
93
+ return 1.0 / frequency
94
+ end
75
95
  end
76
96
 
77
97
  # Calculates the refractive index of a substance given angle of incidence and angle of refraction.
78
98
  # @param angle_of_incidence [Int, Float]
79
99
  # angle_of_incidence is in degrees
80
100
  # @param angle_of_refraction [Int, Float]
81
- # angle_of_refraction is in degrees
101
+ # angle_of_refraction != 0; angle_of_refraction is in degrees
82
102
  # @return [Float]
103
+ # @raise [ZeroDivisionError] if angle_of_refraction = 0
83
104
  # @example
84
105
  # Joules.refractive_index_v1(50, 35) #=> 1.3355577296591308
85
106
  # @note There is one other method for calculating refractive index.
86
107
  def refractive_index_v1(angle_of_incidence, angle_of_refraction)
87
- return Math.sin(to_radians(angle_of_incidence)) /
88
- Math.sin(to_radians(angle_of_refraction))
108
+ if angle_of_refraction.zero?
109
+ raise ZeroDivisionError.new('divided by 0')
110
+ else
111
+ return Math.sin(to_radians(angle_of_incidence)) /
112
+ Math.sin(to_radians(angle_of_refraction))
113
+ end
89
114
  end
90
115
 
91
116
  # Calculates the refractive index of a substance given critical angle.
92
117
  # @param critical_angle [Int, Float]
93
118
  # critical_angle != 0; critical_angle is in degrees
94
119
  # @return [Float]
120
+ # @raise [ZeroDivisionError] if critical_angle = 0
95
121
  # @example
96
122
  # Joules.refractive_index_v2(48.7535) #=> 1.3299993207924483
97
123
  # @note There is one other method for calculating refractive index.
98
124
  def refractive_index_v2(critical_angle)
99
- return 1.0 / Math.sin(to_radians(critical_angle))
125
+ if critical_angle.zero?
126
+ raise ZeroDivisionError.new('divided by 0')
127
+ else
128
+ return 1.0 / Math.sin(to_radians(critical_angle))
129
+ end
100
130
  end
101
131
 
102
132
  # Calculates the magnification given image height and object height.
@@ -106,34 +136,49 @@ module Joules
106
136
  # object_height > 0; object_height has the same units as image_height
107
137
  # @return [Float]
108
138
  # return value >= 0
139
+ # @raise [ZeroDivisionError] if object_height = 0
109
140
  # @example
110
141
  # Joules.magnification(10, 5) #=> 2.0
111
142
  def magnification(image_height, object_height)
112
- return image_height / object_height.to_f
143
+ if object_height.zero?
144
+ raise ZeroDivisionError.new('divided by 0')
145
+ else
146
+ return image_height / object_height.to_f
147
+ end
113
148
  end
114
149
 
115
150
  # Calculates the focal length of a lens given object distance and image distance.
116
151
  # @param object_distance [Int, Float]
117
- # object_distance > 0; object_distance is in meters
152
+ # object_distance > 0; object_distance is in metres
118
153
  # @param image_distance [Int, Float]
119
- # image_distance > 0; image_distance is in meters
154
+ # image_distance > 0; image_distance is in metres
120
155
  # @return [Float]
121
- # return value >= 0; return value is in meters
156
+ # return value >= 0; return value is in metres
157
+ # @raise [ZeroDivisionError] if object_distance = 0 or image_distance = 0
122
158
  # @example
123
159
  # Joules.focal_length(45.7, 22.8) #=> 15.21109489051095
124
160
  def focal_length(object_distance, image_distance)
125
- return 1 / ((1.0 / object_distance) + (1.0 / image_distance))
161
+ if object_distance.zero? || image_distance.zero?
162
+ raise ZeroDivisionError.new('divided by 0')
163
+ else
164
+ return 1 / ((1.0 / object_distance) + (1.0 / image_distance))
165
+ end
126
166
  end
127
167
 
128
168
  # Calculates the power of a lens given focal length.
129
169
  # @param focal_length [Int, Float]
130
- # focal_length > 0; focal_length is in meters
170
+ # focal_length > 0; focal_length is in metres
131
171
  # @return [Float]
132
172
  # return value > 0; return value is in dioptres
173
+ # @raise [ZeroDivisionError] if focal_length = 0
133
174
  # @example
134
175
  # Joules.power_of_lens(2) #=> 0.5
135
176
  def power_of_lens(focal_length)
136
- return 1.0 / focal_length
177
+ if focal_length.zero?
178
+ raise ZeroDivisionError.new('divided by 0')
179
+ else
180
+ return 1.0 / focal_length
181
+ end
137
182
  end
138
183
 
139
184
  end
data/lib/joules.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing Physics formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.3.1 01/06/2015
6
+ # @version: 0.3.2 03/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Joules module (joules.rb)
@@ -15,6 +15,7 @@ require 'joules/density'
15
15
  require 'joules/forces'
16
16
  require 'joules/momentum_impulse'
17
17
  require 'joules/energy_work_power'
18
+ require 'joules/stress_strain'
18
19
  require 'joules/pressure'
19
20
  require 'joules/thermodynamics'
20
21
  require 'joules/waves'
@@ -22,5 +23,6 @@ require 'joules/electricity'
22
23
  require 'joules/quantum'
23
24
  require 'joules/gravitational_fields'
24
25
  require 'joules/electric_fields'
26
+ require 'joules/magnetic_fields'
25
27
  require 'joules/geometry'
26
28
  require 'joules/conversion'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joules
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elisha Lai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-01 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " Joules is a library (gem) for providing simple Physics formulas\n
14
14
  \ in kinematics, forces, waves, electricity, and so much more. A\n selection
@@ -31,10 +31,12 @@ files:
31
31
  - lib/joules/geometry.rb
32
32
  - lib/joules/gravitational_fields.rb
33
33
  - lib/joules/kinematics.rb
34
+ - lib/joules/magnetic_fields.rb
34
35
  - lib/joules/mass_weight.rb
35
36
  - lib/joules/momentum_impulse.rb
36
37
  - lib/joules/pressure.rb
37
38
  - lib/joules/quantum.rb
39
+ - lib/joules/stress_strain.rb
38
40
  - lib/joules/thermodynamics.rb
39
41
  - lib/joules/waves.rb
40
42
  homepage: http://elailai94.github.io/Joules