Class: Numbers
Class Method Summary collapse
- .enter_as_added ⇒ Object
- .menu ⇒ Object
- .sum_dollars(txt) ⇒ Object
- .sum_dollars_in_clipboard ⇒ Object
- .sum_numbers(txt) ⇒ Object
- .sum_numbers_in_clipboard ⇒ Object
Class Method Details
.enter_as_added ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/xiki/numbers.rb', line 28 def self.enter_as_added txt = Clipboard[0] # If it has amount after " = ", make nure only they are added if txt =~ / = \$?\d/ txt.gsub! /.* = /, '' end # If it has dollars, just add dollars if txt =~ /\$\d/ View.insert self.sum_dollars(txt).to_s return end View.insert self.sum_numbers(txt).to_s end |
.menu ⇒ Object
2 3 4 5 6 |
# File 'lib/xiki/numbers.rb', line 2 def self. ['.sum_numbers_in_clipboard', '.sum_dollars_in_clipboard' ] end |
.sum_dollars(txt) ⇒ Object
18 19 20 21 22 |
# File 'lib/xiki/numbers.rb', line 18 def self.sum_dollars txt numbers = txt.scan(/\$([\d.]+)/).map{|o| o.first} numbers.map!{|o| o.to_f} numbers.inject(0){|i, o| i + o} end |
.sum_dollars_in_clipboard ⇒ Object
24 25 26 |
# File 'lib/xiki/numbers.rb', line 24 def self.sum_dollars_in_clipboard self.sum_dollars Clipboard[0] end |
.sum_numbers(txt) ⇒ Object
8 9 10 11 12 |
# File 'lib/xiki/numbers.rb', line 8 def self.sum_numbers txt numbers = txt.scan(/[\d.]+/) numbers.map!{|o| o.to_f} numbers.inject(0){|i, o| i + o} end |