column_lookup.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Created by IntelliJ IDEA.
  2. # User: mrs
  3. # Date: 6/20/15
  4. # Time: 4:33 PM
  5. # To change this template use File | Settings | File Templates.
  6. java_import com.jbidwatcher.ui.table.TableColumnController
  7. class ColumnLookup
  8. LOOKUP_MAP = {
  9. TableColumnController::ID => proc { |aEntry| aEntry.identifier },
  10. TableColumnController::CUR_BID => :current_bid.to_proc,
  11. TableColumnController::SNIPE_OR_MAX => :format_snipe_and_bid.to_proc,
  12. TableColumnController::MAX => :max_bid.to_proc,
  13. TableColumnController::SNIPE => proc { |aEntry|},
  14. TableColumnController::TIME_LEFT => proc { |aEntry|},
  15. TableColumnController::END_DATE => proc { |aEntry|},
  16. TableColumnController::TITLE => proc { |aEntry|},
  17. TableColumnController::STATUS => proc { |aEntry|},
  18. TableColumnController::THUMBNAIL => proc { |aEntry|},
  19. TableColumnController::SELLER => proc { |aEntry|},
  20. TableColumnController::COMMENT => proc { |aEntry|},
  21. TableColumnController::BIDDER => proc { |aEntry|},
  22. TableColumnController::FIXED_PRICE => proc { |aEntry|},
  23. TableColumnController::SHIPPING_INSURANCE => proc { |aEntry|},
  24. TableColumnController::ITEM_LOCATION => proc { |aEntry|},
  25. TableColumnController::BIDCOUNT => proc { |aEntry|},
  26. TableColumnController::JUSTPRICE => proc { |aEntry|},
  27. TableColumnController::SELLER_FEEDBACK => proc { |aEntry|},
  28. TableColumnController::SELLER_POSITIVE_FEEDBACK => proc { |aEntry|},
  29. TableColumnController::CUR_TOTAL => proc { |aEntry|},
  30. TableColumnController::SNIPE_TOTAL => proc { |aEntry|}
  31. }
  32. def max_bid(entry)
  33. entry.bid_on? ? format_bid(entry, error_note(entry)) : "n/a"
  34. end
  35. def current_bid(aEntry)
  36. cur_price = aEntry.current_price
  37. if aEntry.fixed?
  38. quantity = aEntry.quantity > 1 ? " x #{aEntry.quantity}" : ""
  39. "#{cur_price} (FP#{quantity})"
  40. else
  41. "#{cur_price} (#{aEntry.num_bidders})"
  42. end
  43. end
  44. def get_value(entry, col_num)
  45. method = LOOKUP_MAP[col_num]
  46. if method.arity == 1
  47. method.call(entry)
  48. else
  49. method.call(self, entry)
  50. end
  51. end
  52. private
  53. def error_note(aEntry)
  54. aEntry.error_page.nil? ? "" : "*"
  55. end
  56. def format_bid(entry, note)
  57. "#{note}#{entry.get_bid}"
  58. end
  59. end