tbmx 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/tbmx.rb +35 -0
  2. metadata +2 -2
data/lib/tbmx.rb CHANGED
@@ -290,6 +290,14 @@ module TBMX
290
290
  when "bookmarks-folder-id", "bookmarks_folder_id", "bookmarks_folder-id", "bookmarks-folder_id",
291
291
  "bookmark-folder-id", "bookmark_folder_id", "bookmark_folder-id", "bookmark-folder_id"
292
292
  bookmarks_folder_id_command_handler
293
+ when "+"
294
+ addition
295
+ when "-"
296
+ subtraction
297
+ when "*"
298
+ multiplication
299
+ when "/"
300
+ division
293
301
  else
294
302
  command_error "unknown command #{command.to_html}"
295
303
  end
@@ -303,6 +311,33 @@ module TBMX
303
311
  %{<a href="#{TB_COM}/#{target}">#{string}</a>}
304
312
  end
305
313
 
314
+ def reducable_math_function_handler(function)
315
+ expressions
316
+ .map do |number|
317
+ begin
318
+ Float(number.to_html)
319
+ rescue ArgumentError
320
+ nil
321
+ end
322
+ end.reject(&:nil?).reduce(function)
323
+ end
324
+
325
+ def addition
326
+ reducable_math_function_handler :+
327
+ end
328
+
329
+ def subtraction
330
+ reducable_math_function_handler :-
331
+ end
332
+
333
+ def multiplication
334
+ reducable_math_function_handler :*
335
+ end
336
+
337
+ def division
338
+ reducable_math_function_handler :/
339
+ end
340
+
306
341
  def user_command_handler
307
342
  user = expressions.select {|expr| expr.is_a? WordToken}.first
308
343
  if not user
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tbmx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-09 00:00:00.000000000 Z
12
+ date: 2014-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport