sumtotal 0.1.0

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTllYmY0ZmI5NzBlY2ZhYjViNDI1MjQzYjQxYzMzZWYxNWRkODgzOA==
5
+ data.tar.gz: !binary |-
6
+ Y2JmNjdiNmJiNjViNjdmYjFhMjc2ZDc0ODhiMDdkM2UwZmE5MjQ3OA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YWU3ZWU3ZWI5NDE3YjhkNmM0YTI3MzI2MzRiMDU2ZGJlZjdjOWE4N2QwMGUw
10
+ ZWMwOTlkNWY3MzBlZTJhNTNkN2YxOWFiN2QyZThiMWNkZjhjOTBmZDE0NjM0
11
+ MDY3N2RiMjUxYmY1OWM3MWFjMDM0ZDVjNzdjOGNmZGFkMTE1ZGM=
12
+ data.tar.gz: !binary |-
13
+ NTg0ODBiZDJiMDVlNWFhZjg3MjJjNmViOGEwMWMxMjNjMGI1OWQzMmE4Mjhh
14
+ OGNiMWZlOWViODc0YjZiODdkZTU4ODRmNGVkM2Q2ZWVkMDM5ZjViOGYzYmQ2
15
+ YjhlODVjNmQ3MmMxNDJhM2RjNmY1NTJhNmY0Njk4NmYwOThlYzA=
@@ -0,0 +1,18 @@
1
+ Sumtotal is a List-Box which displays the contents of a comma-separated text file of two fields, a key and a value. The listbox displays the sum total of the values in the list retrieved from the file.
2
+ For Example, a long list of balances of accounts may be summed in the total entry field.
3
+
4
+ The Listbox has a scrollbar and accommodates a list as long as needed.
5
+
6
+ USAGE:
7
+ ======
8
+ Create a text file containing:
9
+
10
+ ```
11
+ require 'sumtotal'
12
+ Sumtotal.run
13
+ ```
14
+
15
+ save the text file as "sumtotal.rbw" or "sumtotal.rb" on your desktop if you are using Microsoft Windows as an Operating System.
16
+
17
+ if Ruby is in your PATH, clicking on this Ruby file will start the Widget.
18
+
@@ -0,0 +1,21 @@
1
+ $title = 'Sum of Accounts'
2
+ $header = 'Accounts'
3
+ $footer = 'Sum of Accounts'
4
+ filename = 'list.txt'
5
+
6
+ #__________________________ METHODS _________________
7
+ #read a file with comma-separated two fields, and sum the values of second fields
8
+ h = Hash[File.read("#{filename}").split("\n").map{|i| i.split(', ')}]
9
+ $balance = h.values
10
+ $accounts = h.keys
11
+ #transform values of the hash(i.e. second field) to integers
12
+ b_integer = $balance.map{|x| x.to_i}
13
+ #sum the values of the second fields
14
+ $sum = b_integer.inject(:+)
15
+ #add keys names to a variable
16
+ $account_names = TkVariable.new($accounts)
17
+ #add values array to a variable
18
+ $balances = TkVariable.new($balance)
19
+ #add the sum value to a variable with 2 floating points
20
+ $total_sum = TkVariable.new('%.2f' % $sum)
21
+
@@ -0,0 +1,5 @@
1
+ Current Account, 2_809.80
2
+ Saving Account, 4_000.28
3
+ Cash ISA, 14_100.00
4
+ 5y BOND, 20_00.00
5
+ Shares, 1_339.30
@@ -0,0 +1,70 @@
1
+ require 'tk'
2
+ require 'tkextlib/tile'
3
+ require_relative 'accdata'
4
+
5
+ class Sumtotal
6
+ def self.run
7
+ `sumtotal.rb`
8
+ end
9
+ end
10
+ #__________________ ROOT __________________________
11
+ root = TkRoot.new{title "#$title"}
12
+ #_________________________ LISTBOXES __________________________
13
+ #create two listboxes, one for the $account_names and the second for the $balances
14
+ list_left = TkListbox.new(root){
15
+ setgrid 1
16
+ height 15
17
+ width 25
18
+ font TkFont.new('Tahoma 14 normal')
19
+ listvariable $account_names
20
+ }
21
+
22
+ list_right = TkListbox.new(root){
23
+ setgrid 1
24
+ height 15
25
+ width 10
26
+ font TkFont.new('Tahoma 14 normal')
27
+ listvariable $balances
28
+ }
29
+
30
+
31
+ #____________________ SCROLLBARS (right and left) _________________________
32
+ scrollbar = TkScrollbar.new(root){command proc{ |*args|
33
+ list_right.yview(* args)
34
+ list_left.yview(* args)}
35
+ }
36
+
37
+ list_right.yscrollcommand(proc { |first, last|
38
+ scrollbar.set(first, last)})
39
+
40
+ list_left.yscrollcommand(proc { |first, last|
41
+ scrollbar.set(first, last)})
42
+
43
+ #_________________ LABELS _______________________________________
44
+ # Header and footer labels
45
+ header = TkLabel.new(root){
46
+ text "#$header"
47
+ font TkFont.new('Times 14 bold')
48
+ }
49
+
50
+ footer = TkLabel.new(root){
51
+ text "#$footer"
52
+ font TkFont.new('Times 14 bold')
53
+ }
54
+
55
+ #__________________________ TEXT _______________________________
56
+ total = TkEntry.new(root){
57
+ textvariable $total_sum
58
+ font TkFont.new('tahoma 12 bold')
59
+ width 10
60
+ }
61
+ #________________________ GEOMETRY _____________________________
62
+ header.grid('row' => 0, 'columnspan' => 2)
63
+ list_left.grid('row' => 1, 'column' => 1)
64
+ list_right.grid('row' => 1, 'column' => 2)
65
+ scrollbar.grid('row' => 1, 'column'=> 3, 'sticky' => 'NS')
66
+ footer.grid('row' => 23, 'column' => 1)
67
+ total.grid('row' => 23, 'column' =>2, 'stick' => 'NSEW')
68
+ #__________________________ SHOW _______________________________
69
+ Tk.mainloop
70
+ #######################################################
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "sumtotal"
5
+ s.version = "0.1.0"
6
+ s.licenses = ['MIT']
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-21"
10
+ s.description = "A listbox which displays the contents of a comma-separated file and sum the total of the values in the second field."
11
+ s.email = "sabryabdelfattah@gmail.com"
12
+ s.extra_rdoc_files = ["README.md"]
13
+ s.files = ["sumtotal.gemspec", "lib/sumtotal.rb", "README.md", "lib/accdata.rb", "lib/list.txt"]
14
+ s.homepage = "http://sabryfattah.com"
15
+ s.rdoc_options = ["--main", "README.md"]
16
+ s.require_paths = ["lib"]
17
+ s.rubygems_version = "1.8.29"
18
+ s.summary = "A list-box to display the sum-total of the values in the second field of a comma separated list of keys and values in a text file. "
19
+
20
+ if s.respond_to? :specification_version then
21
+ s.specification_version = 3
22
+
23
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
24
+ else
25
+ end
26
+ else
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sumtotal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sabry Fattah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A listbox which displays the contents of a comma-separated file and sum
14
+ the total of the values in the second field.
15
+ email: sabryabdelfattah@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.md
20
+ files:
21
+ - README.md
22
+ - lib/accdata.rb
23
+ - lib/list.txt
24
+ - lib/sumtotal.rb
25
+ - sumtotal.gemspec
26
+ homepage: http://sabryfattah.com
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options:
32
+ - --main
33
+ - README.md
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.4.5
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: A list-box to display the sum-total of the values in the second field of
52
+ a comma separated list of keys and values in a text file.
53
+ test_files: []