summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-04-16 15:34:00 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-04-16 15:34:00 +0000
commit4cb943571abcc1cbcc0fa92d0e8f0f690282ca56 (patch)
treeb16fb963b65aec7dd989ae5c4158649b1177cd6a /lib
parentd22723ed04297175a22b75fec806fa6a1734f299 (diff)
downloadredmine-4cb943571abcc1cbcc0fa92d0e8f0f690282ca56.tar.gz
redmine-4cb943571abcc1cbcc0fa92d0e8f0f690282ca56.zip
Change the case statement into a method call based on the name
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3674 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r--lib/redmine/custom_field_format.rb26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/redmine/custom_field_format.rb b/lib/redmine/custom_field_format.rb
index 29d82b446..336905666 100644
--- a/lib/redmine/custom_field_format.rb
+++ b/lib/redmine/custom_field_format.rb
@@ -30,6 +30,24 @@ module Redmine
self.order = options[:order]
end
+ def format(value)
+ send "format_as_#{name}", value
+ end
+
+ def format_as_date(value)
+ begin; format_date(value.to_date); rescue; value end
+ end
+
+ def format_as_bool(value)
+ l(value == "1" ? :general_text_Yes : :general_text_No)
+ end
+
+ ['string','text','int','float','list'].each do |name|
+ define_method("format_as_#{name}") {|value|
+ return value
+ }
+ end
+
class << self
def map(&block)
yield self
@@ -64,11 +82,9 @@ module Redmine
def format_value(value, field_format)
return "" unless value && !value.empty?
- case field_format
- when "date"
- begin; format_date(value.to_date); rescue; value end
- when "bool"
- l(value == "1" ? :general_text_Yes : :general_text_No)
+
+ if format_type = find_by_name(field_format)
+ format_type.format(value)
else
value
end