joules 0.3.0 → 0.3.1

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,134 +3,137 @@
3
3
  #
4
4
  # @description: Module for providing waves formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.3.0 29/05/2015
6
+ # @version: 0.3.1 01/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Waves module (waves.rb)
10
10
 
11
- require_relative 'conversion'
11
+ module Joules
12
+ module_function
12
13
 
13
- # Calculates the wave speed given frequency and wavelength.
14
- # @param frequency [Int, Float]
15
- # frequency > 0; frequency is in hertz
16
- # @param wavelength [Int, Float]
17
- # wavelength >= 0; wavelength is in meters
18
- # @return [Float]
19
- # return value >= 0; return value is in meters per second
20
- # @example
21
- # wave_speed(3250, 0.1) #=> 325.0
22
- def wave_speed(frequency, wavelength)
23
- return frequency * wavelength.to_f
24
- end
14
+ # Calculates the wave speed given frequency and wavelength.
15
+ # @param frequency [Int, Float]
16
+ # frequency > 0; frequency is in hertz
17
+ # @param wavelength [Int, Float]
18
+ # wavelength >= 0; wavelength is in meters
19
+ # @return [Float]
20
+ # return value >= 0; return value is in meters per second
21
+ # @example
22
+ # Joules.wave_speed(3250, 0.1) #=> 325.0
23
+ def wave_speed(frequency, wavelength)
24
+ return frequency * wavelength.to_f
25
+ end
25
26
 
26
- # Calculates the wavelength given wave speed and frequency.
27
- # @param wave_speed [Int, Float]
28
- # wave_speed >= 0; wave_speed is in meters per second
29
- # @param frequency [Int, Float]
30
- # frequency > 0; frequency is in hertz
31
- # @return [Float]
32
- # return value is in meters
33
- # @example
34
- # wavelength(325, 3250) #=> 0.1
35
- def wavelength(wave_speed, frequency)
36
- return wave_speed / frequency.to_f
37
- end
27
+ # Calculates the wavelength given wave speed and frequency.
28
+ # @param wave_speed [Int, Float]
29
+ # wave_speed >= 0; wave_speed is in meters per second
30
+ # @param frequency [Int, Float]
31
+ # frequency > 0; frequency is in hertz
32
+ # @return [Float]
33
+ # return value is in meters
34
+ # @example
35
+ # Joules.wavelength(325, 3250) #=> 0.1
36
+ def wavelength(wave_speed, frequency)
37
+ return wave_speed / frequency.to_f
38
+ end
38
39
 
39
- # Calculates the frequency given wave speed and wavelength.
40
- # @param wave_speed [Int, Float]
41
- # wave_speed >= 0; wave_speed is in meters per second
42
- # @param wavelength [Int, Float]
43
- # wavelength > 0; wavelength is in meters
44
- # @return [Float]
45
- # return value is in hertz
46
- # @example
47
- # frequency_v1(325, 0.1) #=> 3250.0
48
- # @note There is one other method for calculating frequency.
49
- def frequency_v1(wave_speed, wavelength)
50
- return wave_speed / wavelength.to_f
51
- end
40
+ # Calculates the frequency given wave speed and wavelength.
41
+ # @param wave_speed [Int, Float]
42
+ # wave_speed >= 0; wave_speed is in meters per second
43
+ # @param wavelength [Int, Float]
44
+ # wavelength > 0; wavelength is in meters
45
+ # @return [Float]
46
+ # return value is in hertz
47
+ # @example
48
+ # Joules.frequency_v1(325, 0.1) #=> 3250.0
49
+ # @note There is one other method for calculating frequency.
50
+ def frequency_v1(wave_speed, wavelength)
51
+ return wave_speed / wavelength.to_f
52
+ end
52
53
 
53
- # Calculates the frequency given time period.
54
- # @param time_period [Int, Float]
55
- # time_period > 0; time_period is in seconds
56
- # @return [Float]
57
- # return value > 0; return value is in hertz
58
- # @example
59
- # frequency_v2(12.5) #=> 0.08
60
- # @note There is one other method for calculating frequency.
61
- def frequency_v2(time_period)
62
- return 1.0 / time_period
63
- end
54
+ # Calculates the frequency given time period.
55
+ # @param time_period [Int, Float]
56
+ # time_period > 0; time_period is in seconds
57
+ # @return [Float]
58
+ # return value > 0; return value is in hertz
59
+ # @example
60
+ # Joules.frequency_v2(12.5) #=> 0.08
61
+ # @note There is one other method for calculating frequency.
62
+ def frequency_v2(time_period)
63
+ return 1.0 / time_period
64
+ end
64
65
 
65
- # Calculates the time period given frequency.
66
- # @param frequency [Int, Float]
67
- # frequency > 0; frequency is in hertz
68
- # @return [Float]
69
- # return value > 0; return value is in hertz
70
- # @example
71
- # time_period(0.08) #=> 12.5
72
- def time_period(frequency)
73
- return 1.0 / frequency
74
- end
66
+ # Calculates the time period given frequency.
67
+ # @param frequency [Int, Float]
68
+ # frequency > 0; frequency is in hertz
69
+ # @return [Float]
70
+ # return value > 0; return value is in hertz
71
+ # @example
72
+ # Joules.time_period(0.08) #=> 12.5
73
+ def time_period(frequency)
74
+ return 1.0 / frequency
75
+ end
75
76
 
76
- # Calculates the refractive index of a substance given angle of incidence and angle of refraction.
77
- # @param angle_of_incidence [Int, Float]
78
- # angle_of_incidence is in degrees
79
- # @param angle_of_refraction [Int, Float]
80
- # angle_of_refraction is in degrees
81
- # @return [Float]
82
- # @example
83
- # refractive_index_v1(50, 35) #=> 1.3355577296591308
84
- # @note There is one other method for calculating refractive index.
85
- def refractive_index_v1(angle_of_incidence, angle_of_refraction)
86
- return Math.sin(to_radians(angle_of_incidence)) /
87
- Math.sin(to_radians(angle_of_refraction))
88
- end
77
+ # Calculates the refractive index of a substance given angle of incidence and angle of refraction.
78
+ # @param angle_of_incidence [Int, Float]
79
+ # angle_of_incidence is in degrees
80
+ # @param angle_of_refraction [Int, Float]
81
+ # angle_of_refraction is in degrees
82
+ # @return [Float]
83
+ # @example
84
+ # Joules.refractive_index_v1(50, 35) #=> 1.3355577296591308
85
+ # @note There is one other method for calculating refractive index.
86
+ 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))
89
+ end
89
90
 
90
- # Calculates the refractive index of a substance given critical angle.
91
- # @param critical_angle [Int, Float]
92
- # critical_angle != 0; critical_angle is in degrees
93
- # @return [Float]
94
- # @example
95
- # refractive_index_v2(48.7535) #=> 1.3299993207924483
96
- # @note There is one other method for calculating refractive index.
97
- def refractive_index_v2(critical_angle)
98
- return 1.0 / Math.sin(to_radians(critical_angle))
99
- end
91
+ # Calculates the refractive index of a substance given critical angle.
92
+ # @param critical_angle [Int, Float]
93
+ # critical_angle != 0; critical_angle is in degrees
94
+ # @return [Float]
95
+ # @example
96
+ # Joules.refractive_index_v2(48.7535) #=> 1.3299993207924483
97
+ # @note There is one other method for calculating refractive index.
98
+ def refractive_index_v2(critical_angle)
99
+ return 1.0 / Math.sin(to_radians(critical_angle))
100
+ end
100
101
 
101
- # Calculates the magnification given image_height and object_height.
102
- # @param image_height [Int, Float]
103
- # image_height >= 0; image_height is in a unit of length
104
- # @param object_height [Int, Float]
105
- # object_height > 0; object_height has the same units as image_height
106
- # @return [Float]
107
- # return value >= 0
108
- # @example
109
- # magnification(10, 5) #=> 2.0
110
- def magnification(image_height, object_height)
111
- return image_height / object_height.to_f
112
- end
102
+ # Calculates the magnification given image height and object height.
103
+ # @param image_height [Int, Float]
104
+ # image_height >= 0; image_height is in a unit of length
105
+ # @param object_height [Int, Float]
106
+ # object_height > 0; object_height has the same units as image_height
107
+ # @return [Float]
108
+ # return value >= 0
109
+ # @example
110
+ # Joules.magnification(10, 5) #=> 2.0
111
+ def magnification(image_height, object_height)
112
+ return image_height / object_height.to_f
113
+ end
113
114
 
114
- # Calculates the focal length of a lens given object distance and image distance.
115
- # @param object_distance [Int, Float]
116
- # object_distance > 0; object_distance is in meters
117
- # @param image_distance [Int, Float]
118
- # image_distance > 0; image_distance is in meters
119
- # @return [Float]
120
- # return value >= 0; return value is in meters
121
- # @example
122
- # focal_length(45.7, 22.8) #=> 15.21109489051095
123
- def focal_length(object_distance, image_distance)
124
- return 1 / ((1.0 / object_distance) + (1.0 / image_distance))
125
- end
115
+ # Calculates the focal length of a lens given object distance and image distance.
116
+ # @param object_distance [Int, Float]
117
+ # object_distance > 0; object_distance is in meters
118
+ # @param image_distance [Int, Float]
119
+ # image_distance > 0; image_distance is in meters
120
+ # @return [Float]
121
+ # return value >= 0; return value is in meters
122
+ # @example
123
+ # Joules.focal_length(45.7, 22.8) #=> 15.21109489051095
124
+ def focal_length(object_distance, image_distance)
125
+ return 1 / ((1.0 / object_distance) + (1.0 / image_distance))
126
+ end
127
+
128
+ # Calculates the power of a lens given focal length.
129
+ # @param focal_length [Int, Float]
130
+ # focal_length > 0; focal_length is in meters
131
+ # @return [Float]
132
+ # return value > 0; return value is in dioptres
133
+ # @example
134
+ # Joules.power_of_lens(2) #=> 0.5
135
+ def power_of_lens(focal_length)
136
+ return 1.0 / focal_length
137
+ end
126
138
 
127
- # Calculates the power of a lens given focal length.
128
- # @param focal_length [Int, Float]
129
- # focal_length > 0; focal_length is in meters
130
- # @return [Float]
131
- # return value > 0; return value is in dioptres
132
- # @example
133
- # power_of_lens(2) #=> 0.5
134
- def power_of_lens(focal_length)
135
- return 1.0 / focal_length
136
139
  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.0 29/05/2015
6
+ # @version: 0.3.1 01/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Joules module (joules.rb)
@@ -20,5 +20,7 @@ require 'joules/thermodynamics'
20
20
  require 'joules/waves'
21
21
  require 'joules/electricity'
22
22
  require 'joules/quantum'
23
+ require 'joules/gravitational_fields'
24
+ require 'joules/electric_fields'
23
25
  require 'joules/geometry'
24
26
  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.0
4
+ version: 0.3.1
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-05-29 00:00:00.000000000 Z
11
+ date: 2015-06-01 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
@@ -18,15 +18,18 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - LICENSE.md
21
22
  - README.md
22
23
  - lib/joules.rb
23
24
  - lib/joules/constants.rb
24
25
  - lib/joules/conversion.rb
25
26
  - lib/joules/density.rb
27
+ - lib/joules/electric_fields.rb
26
28
  - lib/joules/electricity.rb
27
29
  - lib/joules/energy_work_power.rb
28
30
  - lib/joules/forces.rb
29
31
  - lib/joules/geometry.rb
32
+ - lib/joules/gravitational_fields.rb
30
33
  - lib/joules/kinematics.rb
31
34
  - lib/joules/mass_weight.rb
32
35
  - lib/joules/momentum_impulse.rb