joules 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c20098c6f822a1b455a45e4a0a569545939be0c0
4
+ data.tar.gz: 13cf60542b4b7dd226b6d4da3ea265982734ef8d
5
+ SHA512:
6
+ metadata.gz: b74fffa6a1b01114f96bf41f3c62855ca461007cfd63fe824f38eb53d5294c9e6d9090c1e81d344cc43e75aa5f8b7d073992969bf2067e266dfcdd62ba824e75
7
+ data.tar.gz: cec724aa534074607f287b5cfb606d35a4d1d10e658515c880d78631e8dd080ad681d0f727970e87187cc9a47ad68b93081af7647ccedfe740cb6c283142a708
@@ -0,0 +1,17 @@
1
+ #==============================================================================
2
+ # Joules
3
+ #
4
+ # @description: Module for providing constants
5
+ # @author: Elisha Lai
6
+ # @version: 0.0.2 16/05/2015
7
+ #==============================================================================
8
+
9
+ # Constants module (constants.rb)
10
+
11
+ # Speed of light in free space
12
+ # Note: This quantity is in meters per second.
13
+ SPEED_OF_LIGHT = 3.00e8
14
+
15
+ # Acceleration of free fall
16
+ # Note: This quantity is in meters per second squared.
17
+ FREE_FALL_ACCELERATION = 9.81
@@ -0,0 +1,24 @@
1
+ #==============================================================================
2
+ # Joules
3
+ #
4
+ # @description: Module for providing density formulas
5
+ # @author: Elisha Lai
6
+ # @version: 0.0.2 16/05/2015
7
+ #==============================================================================
8
+
9
+ # Density module (density.rb)
10
+
11
+ # density: (union Int Float) (union Int Float) -> Float
12
+ # Conditions:
13
+ # PRE: mass >= 0
14
+ # mass is in kilograms.
15
+ # volume > 0
16
+ # volume is in meters cubed.
17
+ # POST: Returns a Float.
18
+ # returned value >= 0
19
+ # returned value is in kilograms per meter cubed.
20
+ # Purpose: Consumes two numbers, mass and volume. Returns the
21
+ # calculated density.
22
+ def density(mass, volume)
23
+ return mass / volume.to_f
24
+ end
@@ -0,0 +1,108 @@
1
+ #==============================================================================
2
+ # Joules
3
+ #
4
+ # @description: Module for providing energy, work, and power formulas
5
+ # @author: Elisha Lai
6
+ # @version: 0.0.2 16/05/2015
7
+ #==============================================================================
8
+
9
+ # Energy, work, and power module (energy_work_power.rb)
10
+
11
+ require_relative 'constants'
12
+
13
+ # gravitational_potential_energy: (union Int Float) (union Int Float)
14
+ # -> Float
15
+ # Conditions:
16
+ # PRE: mass >= 0
17
+ # mass is in kilograms.
18
+ # height >= 0
19
+ # height is in meters.
20
+ # POST: Returns a Float.
21
+ # returned value >= 0
22
+ # returned value is in joules.
23
+ # Purpose: Consumes two numbers, mass and height. Returns the calculated
24
+ # gravitational potential energy.
25
+ def gravitational_potential_energy(mass, height)
26
+ return mass * FREE_FALL_ACCELERATION * height
27
+ end
28
+
29
+ # elastic_potential_energy: (union Int Float) (union Int Float) -> Float
30
+ # Conditions:
31
+ # PRE: spring_constant >= 0
32
+ # spring constant is in newtons per meter.
33
+ # extension >= 0
34
+ # extension is in meters.
35
+ # POST: Returns a Float.
36
+ # returned value >= 0
37
+ # returned value is in joules.
38
+ # Purpose: Consumes two numbers, spring_constant and extension. Returns
39
+ # the calculated elastic potential energy.
40
+ def elastic_potential_energy(spring_constant, extension)
41
+ return 0.5 * spring_constant * (extension ** 2)
42
+ end
43
+
44
+ # kinetic_energy: (union Int Float) (union Int Float) -> Float
45
+ # Conditions:
46
+ # PRE: mass >= 0
47
+ # mass is in kilograms.
48
+ # velocity is in meters per second.
49
+ # POST: Returns a Float.
50
+ # returned value >= 0
51
+ # returned value is in joules.
52
+ # Purpose: Consumes two numbers, mass and velocity. Returns the calculated
53
+ # kinetic energy.
54
+ def kinetic_energy(mass, velocity)
55
+ return 0.5 * mass * (velocity ** 2)
56
+ end
57
+
58
+ # work_done: (union Int Float) (union Int Float) -> Float
59
+ # Conditions:
60
+ # PRE: force is in newtons.
61
+ # distance >= 0
62
+ # distance is in meters.
63
+ # POST: Returns a Float.
64
+ # returned value is in joules.
65
+ # Purpose: Consumes two numbers, force and distance. Returns the
66
+ # calculated work done.
67
+ def work_done(force, distance)
68
+ return force * distance.to_f
69
+ end
70
+
71
+ # power: (union Int Float) (union Int Float) -> Float
72
+ # Condition:
73
+ # PRE: work_done is in joules.
74
+ # time > 0
75
+ # time is in seconds.
76
+ # POST: Returns a Float.
77
+ # returned value is in watts.
78
+ # Purpose: Consumes two numbers, work done and time. Returns the
79
+ # calculated power.
80
+ def power(work_done, time)
81
+ return work_done / time.to_f
82
+ end
83
+
84
+ # energy_efficiency: (union Int Float) (union Int Float) -> Float
85
+ # Conditions:
86
+ # PRE: energy_input > 0
87
+ # 0 <= useful_energy_output <= energy_input
88
+ # useful_energy_output and energy_input are in joules.
89
+ # POST: Returns a Float.
90
+ # returned value >= 0
91
+ # Purpose: Consumes two numbers, useful_energy_output and energy_input.
92
+ # Returns the calculated energy efficiency.
93
+ def energy_efficiency(useful_energy_output, energy_input)
94
+ return (useful_energy_output / energy_input.to_f) * 100
95
+ end
96
+
97
+ # power_efficiency: (union Int Float) (union Int Float) -> Float
98
+ # Conditions:
99
+ # PRE: power_input > 0
100
+ # 0 <= useful_power_output <= power_input
101
+ # useful_power_output and power_input are in joules.
102
+ # POST: Returns a Float.
103
+ # returned value >= 0
104
+ # Purpose: Consumes two numbers, useful_power_output and power_input.
105
+ # Returns the calculated power efficiency.
106
+ def power_efficiency(useful_power_output, power_input)
107
+ return (useful_power_output / power_input.to_f) * 100
108
+ end
@@ -0,0 +1,65 @@
1
+ #==============================================================================
2
+ # Joules
3
+ #
4
+ # @description: Module for providing forces formulas
5
+ # @author: Elisha Lai
6
+ # @version: 0.0.2 16/05/2015
7
+ #==============================================================================
8
+
9
+ # Forces module (forces.rb)
10
+
11
+ # force_v1: (union Int Float) (union Int Float) -> Float
12
+ # Conditions:
13
+ # PRE: mass >= 0
14
+ # mass is in kilograms.
15
+ # acceleration is in meters per second squared.
16
+ # POST: Returns a Float.
17
+ # returned value is in newtons.
18
+ # Purpose: Consumes two numbers, mass and acceleration. Returns the
19
+ # calculated force.
20
+ def force_v1(mass, acceleration)
21
+ return mass * acceleration.to_f
22
+ end
23
+
24
+ # force_v2: (union Int Float) (union Int Float) -> Float
25
+ # Conditions:
26
+ # PRE: spring_constant >= 0
27
+ # spring constant is in newtons per meter.
28
+ # extension >= 0
29
+ # extension is in meters.
30
+ # POST: Returns a Float.
31
+ # returned value >= 0
32
+ # returned value is in newtons.
33
+ # Purpose: Consumes two numbers, spring_constant and extension. Returns the
34
+ # calculated force.
35
+ def force_v2(spring_constant, extension)
36
+ return spring_constant * extension.to_f
37
+ end
38
+
39
+ # force_v3: (union Int Float) (union Int Float) -> Float
40
+ # Conditions:
41
+ # PRE: initial_velocity and final_velocity are in meters per second.
42
+ # mass >= 0
43
+ # mass is in kilograms.
44
+ # time > 0
45
+ # time is in seconds.
46
+ # POST: Returns a Float.
47
+ # returned value is in newtons.
48
+ # Purpose: Consumes four numbers, initial_velocity, final_velocity, mass,
49
+ # and time. Returns the calculated force.
50
+ def force_v3(initial_velocity, final_velocity, mass, time)
51
+ return ((final_velocity - initial_velocity) * mass) / time.to_f
52
+ end
53
+
54
+ # moment: (union Int Float) (union Int Float) -> Float
55
+ # Conditions:
56
+ # PRE: force is in newtons.
57
+ # distance >= 0
58
+ # distance is in meters.
59
+ # POST: Returns a Float.
60
+ # returned value is in newton metres.
61
+ # Purpose: Consumes two numbers, force and distance. Returns the
62
+ # calculated moment.
63
+ def moment(force, distance)
64
+ return force * distance.to_f
65
+ end
@@ -0,0 +1,124 @@
1
+ #==============================================================================
2
+ # Joules
3
+ #
4
+ # @description: Module for providing kinematics formulas
5
+ # @author: Elisha Lai
6
+ # @version: 0.0.2 16/05/2015
7
+ #==============================================================================
8
+
9
+ # Kinematics module (kinematics.rb)
10
+
11
+ # avg_speed: (union Int Float) (union Int Float) -> Float
12
+ # Conditions:
13
+ # PRE: distance >= 0
14
+ # distance is in meters.
15
+ # time > 0
16
+ # time is in seconds.
17
+ # POST: Returns a Float.
18
+ # returned value >= 0
19
+ # returned value is in meters per second.
20
+ # Purpose: Consumes two numbers, distance and time. Returns the
21
+ # calculated average speed.
22
+ def avg_speed(distance, time)
23
+ return distance / time.to_f
24
+ end
25
+
26
+ # avg_velocity: (union Int Float) (union Int Float) -> Float
27
+ # Conditions:
28
+ # PRE: displacement is in meters.
29
+ # time > 0
30
+ # time is in seconds.
31
+ # POST: Returns a Float.
32
+ # returned value is in meters per second.
33
+ # Purpose: Consumes two numbers, displacement and time. Returns the
34
+ # calculated average velocity.
35
+ def avg_velocity(displacement, time)
36
+ return displacement / time.to_f
37
+ end
38
+
39
+ # acceleration: (union Int Float) (union Int Float) (union Int Float)
40
+ # -> Float
41
+ # Conditions:
42
+ # PRE: initial_velocity and final_velocity are in meters per second.
43
+ # time > 0
44
+ # time is in seconds.
45
+ # POST: Returns a Float.
46
+ # returned value is in meters per second squared.
47
+ # Purpose: Consumes three numbers: initial_velocity, final_velocity,
48
+ # and time. Returns the calculated acceleration.
49
+ def acceleration(initial_velocity, final_velocity, time)
50
+ return (final_velocity - initial_velocity) / time.to_f
51
+ end
52
+
53
+ # final_velocity_v1: (union Int Float) (union Int Float) (union Int Float)
54
+ # -> Float
55
+ # Conditions:
56
+ # PRE: initial_velocity is in meters per second.
57
+ # acceleration is in meters per second squared.
58
+ # time >= 0
59
+ # time is in seconds.
60
+ # POST: Returns a Float.
61
+ # returned value is in meters per second.
62
+ # Purpose: Consumes three numbers: initial_velocity, acceleration, and
63
+ # time. Returns the calculated final velocity.
64
+ def final_velocity_v1(initial_velocity, acceleration, time)
65
+ return initial_velocity + (acceleration * time.to_f)
66
+ end
67
+
68
+ # final_velocity_v2: (union Int Float) (union Int Float) (union Int Float)
69
+ # -> Float
70
+ # Conditions:
71
+ # PRE: initial_velocity is in meters per second.
72
+ # acceleration is in meters per second squared.
73
+ # displacement is in meters.
74
+ # POST: Returns a Float.
75
+ # returned value is in meters per second.
76
+ # Purpose: Consumes three numbers: initial_velocity, acceleration, and
77
+ # displacement. Returns the calculated final velocity.
78
+ def final_velocity_v2(initial_velocity, acceleration, displacement)
79
+ return ((initial_velocity ** 2) + (2 * acceleration * displacement)) ** 0.5
80
+ end
81
+
82
+ # displacement_v1: (union Int Float) (union Int Float) (union Int Float)
83
+ # -> Float
84
+ # Conditions:
85
+ # PRE: initial_velocity and final_velocity are in meters per second.
86
+ # time >= 0
87
+ # time is in seconds.
88
+ # POST: Returns a Float.
89
+ # returned value is in meters.
90
+ # Purpose: Consumes three numbers: initial_velocity, final_velocity, and
91
+ # time. Returns the calculated displacement.
92
+ def displacement_v1(initial_velocity, final_velocity, time)
93
+ return 0.5 * (initial_velocity + final_velocity) * time
94
+ end
95
+
96
+ # displacement_v2: (union Int Float) (union Int Float) (union Int Float)
97
+ # -> Float
98
+ # Conditions:
99
+ # PRE: initial_velocity is in meters per second.
100
+ # acceleration is in meters per second squared.
101
+ # time >= 0
102
+ # time is in seconds.
103
+ # POST: Returns a Float.
104
+ # returned value is in meters.
105
+ # Purpose: Consumes three numbers: initial_velocity, acceleration, and
106
+ # time. Returns the calculated displacement.
107
+ def displacement_v2(initial_velocity, acceleration, time)
108
+ return (initial_velocity * time) + (0.5 * acceleration * (time ** 2))
109
+ end
110
+
111
+ # displacement_v3: (union Int Float) (union Int Float) (union Int Float)
112
+ # -> Float
113
+ # Conditions:
114
+ # PRE: final_velocity is in meters per second.
115
+ # acceleration is in meters per second squared.
116
+ # time >= 0
117
+ # time is in seconds.
118
+ # POST: Returns a Float.
119
+ # returned value is in meters.
120
+ # Purpose: Consumes three numbers: final_velocity, acceleration, and
121
+ # time. Returns the calculated displacement.
122
+ def displacement_v3(final_velocity, acceleration, time)
123
+ return (final_velocity * time) - (0.5 * acceleration * (time ** 2))
124
+ end
@@ -0,0 +1,35 @@
1
+ #==============================================================================
2
+ # Joules
3
+ #
4
+ # @description: Module for providing mass and weight formulas
5
+ # @author: Elisha Lai
6
+ # @version: 0.0.2 16/05/2015
7
+ #==============================================================================
8
+
9
+ # Mass and weight module (mass_weight.rb)
10
+
11
+ require_relative 'constants'
12
+
13
+ # weight: (union Int Float) -> Float
14
+ # Conditions:
15
+ # PRE: mass >= 0
16
+ # mass is in kilograms.
17
+ # POST: Returns a Float.
18
+ # returned value >= 0
19
+ # returned value is in newtons.
20
+ # Purpose: Consumes a number, mass, and returns the calculated weight.
21
+ def weight(mass)
22
+ return mass * FREE_FALL_ACCELERATION
23
+ end
24
+
25
+ # mass: (union Int Float) -> Float
26
+ # Conditions:
27
+ # PRE: weight >= 0
28
+ # weight is in newtons.
29
+ # POST: Returns a Float.
30
+ # returned value >= 0
31
+ # returned value is in kilograms.
32
+ # Purpose: Consumes a numberm weight, and returns the calculated mass.
33
+ def mass(weight)
34
+ return weight / FREE_FALL_ACCELERATION
35
+ end
@@ -0,0 +1,49 @@
1
+ #==============================================================================
2
+ # Joules
3
+ #
4
+ # @description: Module for providing momentum and impulse formulas
5
+ # @author: Elisha Lai
6
+ # @version: 0.0.2 16/05/2015
7
+ #==============================================================================
8
+
9
+ # Momentum and impulse module (momentum_impulse.rb)
10
+
11
+ # momentum: (union Int Float) (union Int Float) -> Float
12
+ # Conditions:
13
+ # PRE: mass >= 0
14
+ # mass is in kilograms.
15
+ # velocity is in meters per second.
16
+ # POST: Returns a Float.
17
+ # returned value is in newton seconds.
18
+ # Purpose: Consumes two numbers, mass and velocity. Returns the calculated
19
+ # momentum.
20
+ def momentum(mass, velocity)
21
+ return mass * velocity.to_f
22
+ end
23
+
24
+ # impulse_v1: (union Int Float) (union Int Float) -> Float
25
+ # Conditions:
26
+ # PRE: force is in newtons.
27
+ # time >= 0
28
+ # time is in seconds.
29
+ # POST: Returns a Float.
30
+ # returned value is in newton seconds.
31
+ # Purpose: Consumes two numbers, force and time. Returns the calculated
32
+ # impulse.
33
+ def impulse_v1(force, time)
34
+ return force * time.to_f
35
+ end
36
+
37
+ # impulse_v2: (union Int Float) (union Int Float) (union Int Float)
38
+ # -> Float
39
+ # Condition:
40
+ # PRE: initial_velocity and final_velocity are in meters per second.
41
+ # mass >= 0
42
+ # mass is in kilograms.
43
+ # POST: Returns a Float.
44
+ # returned value is in newton seconds.
45
+ # Purpose: Consumes three numbers, initial_velocity, final_velocity, and
46
+ # mass. Returns the calculated impulse.
47
+ def impulse_v2(initial_velocity, final_velocity, mass)
48
+ return (final_velocity - initial_velocity) * mass.to_f
49
+ end
@@ -0,0 +1,41 @@
1
+ #==============================================================================
2
+ # Joules
3
+ #
4
+ # @description: Module for providing pressure formulas
5
+ # @author: Elisha Lai
6
+ # @version: 0.0.2 16/05/2015
7
+ #==============================================================================
8
+
9
+ # Pressure module (pressure.rb)
10
+
11
+ require_relative 'constants'
12
+
13
+ # pressure: (union Int Float) (union Int Float) -> Float
14
+ # Conditions:
15
+ # PRE: force >= 0
16
+ # force is in newtons.
17
+ # area > 0
18
+ # area is in meters cubed.
19
+ # POST: Returns a Float.
20
+ # returned value >= 0
21
+ # returned value is in pascals.
22
+ # Purpose: Consumes two numbers, force and area. Returns the calculated
23
+ # pressure.
24
+ def pressure(force, area)
25
+ return force / area.to_f
26
+ end
27
+
28
+ # hydrostatic_pressure: (union Int Float) (union Int Float) -> Float
29
+ # Conditions:
30
+ # PRE: density >= 0
31
+ # density is in kilograms per meter cubed.
32
+ # height >= 0
33
+ # height is in meters.
34
+ # POST: Returns a Float.
35
+ # returned value >= 0
36
+ # returned value is in pascals.
37
+ # Purpose: Consumes two numbers, density and height. Returns the calculated
38
+ # hydrostatic pressure.
39
+ def hydrostatic_pressure(density, height)
40
+ return density * FREE_FALL_ACCELERATION * height
41
+ end
data/lib/joules.rb ADDED
@@ -0,0 +1,18 @@
1
+ #==============================================================================
2
+ # Joules
3
+ #
4
+ # @description: Module for providing Physics formulas
5
+ # @author: Elisha Lai
6
+ # @version: 0.0.2 16/05/2015
7
+ #==============================================================================
8
+
9
+ # Joules module (joules.rb)
10
+
11
+ require 'joules/constants'
12
+ require 'joules/kinematics'
13
+ require 'joules/mass_weight'
14
+ require 'joules/density'
15
+ require 'joules/forces'
16
+ require 'joules/momentum_impulse'
17
+ require 'joules/energy_work_power'
18
+ require 'joules/pressure'
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: joules
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Elisha Lai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: " Joules is a library (gem) for providing simple Physics formulas\n
14
+ \ in kinematics, forces, waves, electricity, and so much more. A\n selection
15
+ of fundamental constants are also provided. It is \n written entirely in Ruby.\n"
16
+ email: elisha.lai@outlook.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/joules.rb
22
+ - lib/joules/constants.rb
23
+ - lib/joules/density.rb
24
+ - lib/joules/energy_work_power.rb
25
+ - lib/joules/forces.rb
26
+ - lib/joules/kinematics.rb
27
+ - lib/joules/mass_weight.rb
28
+ - lib/joules/momentum_impulse.rb
29
+ - lib/joules/pressure.rb
30
+ homepage: http://elailai94.github.io/Joules
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.4.7
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: A library (gem) for providing Physics formulas
54
+ test_files: []