BMI_calc 0.1.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.
Files changed (5) hide show
  1. checksums.yaml +15 -0
  2. data/BMI_calc.gemspec +29 -0
  3. data/README.md +15 -0
  4. data/lib/BMI_calc.rb +147 -0
  5. metadata +51 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWQ2MTgwMDk4MGE4ZTRhYzAxODhkYmRkMGM0ZmI5MjYyYWJkMDFlNQ==
5
+ data.tar.gz: !binary |-
6
+ MTU2ZWMxOTNkNWRmMTA3MTAwMzUxN2JjY2UzZjhiMTYwOTdiODU1ZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MGE3MjA1ZTIzOWM2YzljMzcwYWY4MjM0NTdiNjUwMjk5YmE2NzVlN2ZjZDlh
10
+ NTE5ZWM2MDYyYmNkM2VhMjUxNWRlNmQ0OTFlOTI1MDRmNzJjZTI2MjY4ZGUw
11
+ NzdhOTA2NjUxMDRmNWVhNmYzZmQ0ZTNlNWJjNWViNDUxZmFjZDI=
12
+ data.tar.gz: !binary |-
13
+ MjNmOTNjMmFjMjE1YTBhYjUzZDNkZDRiOWQ1NWYwZTdlZDJkMTZlMDg4MzQ3
14
+ ZTkwZDliMDI5YWUyNjgzZTI3Njc4NDhjYTBlNWE2ODlhOGYzZTRmNDE1MWI5
15
+ NDdlNjgyYmZjNjg0YjI5Nzg0NDk4N2Q1MjcwOWNmNzM1NTU2MGI=
data/BMI_calc.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "BMI_calc"
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Sabry Fattah"]
9
+ s.date = "2015-02-14"
10
+ s.description = "BMI calculator using Tcl/Tk graphical user interface"
11
+ s.extra_rdoc_files = ["README.md"]
12
+ s.files = ["BMI_calc.gemspec", "lib/BMI_calc.rb", "README.md"]
13
+ s.homepage = "http://sabryfattah.com"
14
+ s.email = "sabryabdelfattah@gmail.com"
15
+ s.rdoc_options = ["--main", "README.md"]
16
+ s.require_paths = ["lib"]
17
+ s.rubygems_version = "1.8.29"
18
+ s.licenses = ['MIT']
19
+ s.summary = "BMI_calc is BMI calculator using Tcl/Tk graphical user interface to build a form where you enter the Weight in Kilograms and height in Centimeters to get the BMI and an advice about your weight."
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ else
26
+ end
27
+ else
28
+ end
29
+ end
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ BMI_calc is BMI calculator using Tcl/Tk graphical user interface to build a form where you enter the Weight in Kilograms and height in Centimeters to get the BMI and an advice about your weight.
2
+
3
+ USAGE:
4
+ ======
5
+ Create a text file containing:
6
+
7
+ ```
8
+ require 'BMI_calc'
9
+ BMI.run
10
+ ```
11
+
12
+ save the text file as BMI.rb pn your desktop.
13
+
14
+ if Ruby is in your PATH, clicking on this Ruby file will start the Widget.
15
+
data/lib/BMI_calc.rb ADDED
@@ -0,0 +1,147 @@
1
+ require 'tk'
2
+ #___________ Run Script ______________
3
+ class BMI
4
+ def self.run
5
+ `ruby "C:/Ruby193/lib/ruby/gems/1.9.1/gems/BMI_calc-0.1.0/lib/BMI_calc.rb"`
6
+ end
7
+ end
8
+
9
+ end
10
+ #################### Main Window ########################
11
+ root = TkRoot.new{title "BMI Calculator"}
12
+ ################### Variables ########################
13
+ $w =TkVariable.new
14
+ $h =TkVariable.new
15
+ $bmi =TkVariable.new
16
+ $j =TkVariable.new
17
+ #____________________ BUTTON ______________________________________
18
+ button = TkButton.new(root) {
19
+ text 'Calculate BMI'
20
+ command(proc{bmi($w, $h); judgement($bmi)})
21
+ background "white"
22
+ borderwidth 4
23
+ font TkFont.new('times 14 bold')
24
+ foreground "black"
25
+ 'padx' '10'
26
+ 'pady' '15'
27
+ relief 'raised'
28
+ }
29
+
30
+ #__________________________ METHODS _______________________________
31
+ def bmi(w, h)
32
+ h = (h.to_f)/100
33
+ w = (w.to_f)/100
34
+ $bmi.value= (w/(h**2)).round(2)
35
+ end
36
+
37
+ def judgement(bmi)
38
+ if bmi < 0.18
39
+ judgment = "You are underweight"
40
+ elsif bmi >= 0.18 && bmi < 0.25
41
+ judgment = "You have normal Weight"
42
+ elsif bmi > 0.25
43
+ judgment = "You are over-weight"
44
+ end
45
+
46
+ $j.value = "#{judgment}"
47
+
48
+ end
49
+
50
+ ###################### LABELS ##########################
51
+ w = TkLabel.new(root) do
52
+ text "Weight in Kg"
53
+ background "green"
54
+ borderwidth 4
55
+ font TkFont.new('times 14 bold')
56
+ foreground "black"
57
+ 'padx' '10'
58
+ 'pady' '15'
59
+ relief 'raised'
60
+ end
61
+
62
+ h = TkLabel.new(root) do
63
+ text "Height in cm"
64
+ background "green"
65
+ borderwidth 4
66
+ font TkFont.new('times 14 bold')
67
+ foreground "black"
68
+ 'padx' '10'
69
+ 'pady' '15'
70
+ relief 'raised'
71
+ end
72
+
73
+ g = TkLabel.new(root) do
74
+ text "BMI"
75
+ background "Orange"
76
+ borderwidth 4
77
+ font TkFont.new('times 14 bold')
78
+ foreground "black"
79
+ 'padx' '10'
80
+ 'pady' '15'
81
+ relief 'raised'
82
+ end
83
+
84
+
85
+ ################### Entry Fields #######################
86
+ w_entry = TkEntry.new(root){
87
+ text " "
88
+ background "yellow"
89
+ borderwidth 4
90
+ font TkFont.new('times 14 bold')
91
+ foreground "black"
92
+ relief 'groove'
93
+ textvariable $w
94
+ }
95
+
96
+ h_entry = TkEntry.new(root){
97
+ text " "
98
+ background "yellow"
99
+ borderwidth 4
100
+ font TkFont.new('times 14 bold')
101
+ foreground "black"
102
+ relief 'groove'
103
+ textvariable $h
104
+ }
105
+ #______________________________ TEXT ___________________________________
106
+ g_label = TkLabel.new(root){
107
+ background "yellow"
108
+ borderwidth 4
109
+ font TkFont.new('tahoma 12 bold')
110
+ foreground "black"
111
+ relief 'groove'
112
+ textvariable $bmi
113
+ width 10
114
+ height 1
115
+ }
116
+
117
+ judgement = TkLabel.new(root){
118
+ background "yellow"
119
+ borderwidth 4
120
+ font TkFont.new('tahoma 12 bold')
121
+ foreground "black"
122
+ relief 'groove'
123
+ textvariable $j
124
+ wraplength 200
125
+ width 15
126
+ height 3
127
+ }
128
+
129
+ ##################### Geometry ##################################
130
+ # Labels
131
+ w.grid('row' => 0, 'column' => 0, 'sticky' => 'we')
132
+ h.grid('row' => 1, 'column' => 0, 'sticky' => 'we')
133
+ g.grid('row' => 2, 'column' => 0, 'sticky' => 'we')
134
+
135
+ #button
136
+ button.grid('row' => 3, 'column' => 0, 'sticky' => 'we')
137
+
138
+ #entries
139
+ w_entry.grid('row' => 0, 'column' => 1, 'sticky' => 'we')
140
+ h_entry.grid('row' => 1, 'column' => 1, 'sticky' => 'we')
141
+ g_label.grid('row' => 2, 'column' => 1, 'sticky' => 'we')
142
+ judgement.grid('row' => 3, 'column' => 1, 'sticky' => 'we')
143
+
144
+ #_______________________________________ Show __________________________________
145
+ Tk.mainloop
146
+
147
+ ##############################################################
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: BMI_calc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Sabry Fattah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: BMI calculator using Tcl/Tk graphical user interface
14
+ email: sabryabdelfattah@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files:
18
+ - README.md
19
+ files:
20
+ - BMI_calc.gemspec
21
+ - README.md
22
+ - lib/BMI_calc.rb
23
+ homepage: http://sabryfattah.com
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options:
29
+ - --main
30
+ - README.md
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>'
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.4.5
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: BMI_calc is BMI calculator using Tcl/Tk graphical user interface to build
49
+ a form where you enter the Weight in Kilograms and height in Centimeters to get
50
+ the BMI and an advice about your weight.
51
+ test_files: []