aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/public_body.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/public_body.rb')
-rw-r--r--app/models/public_body.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 65acb407b..c89309b48 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -188,6 +188,7 @@ class PublicBody < ActiveRecord::Base
# XXX This immediately saves the new tags.
def tag_string=(tag_string)
tag_string = tag_string.strip
+ # split tags apart
tags = tag_string.split(/\s+/).uniq
ActiveRecord::Base.transaction do
@@ -196,14 +197,23 @@ class PublicBody < ActiveRecord::Base
end
self.public_body_tags = []
for tag in tags
- public_body_tag = PublicBodyTag.new(:name => tag)
+ # see if is a machine tags (i.e. a tag which has a value)
+ sections = tag.split(/:/)
+ name = sections[0]
+ if sections[1]
+ value = sections[1,sections.size].join(":")
+ else
+ value = nil
+ end
+
+ public_body_tag = PublicBodyTag.new(:name => name, :value => value)
self.public_body_tags << public_body_tag
public_body_tag.public_body = self
end
end
end
def tag_string
- return self.public_body_tags.map { |t| t.name }.join(' ')
+ return self.public_body_tags.map { |t| t.name_and_value }.join(' ')
end
def has_tag?(tag)
for public_body_tag in self.public_body_tags
@@ -213,6 +223,14 @@ class PublicBody < ActiveRecord::Base
end
return false
end
+ def get_tag_value(tag)
+ for public_body_tag in self.public_body_tags
+ if public_body_tag.name == tag
+ return public_body_tag.value
+ end
+ end
+ return false
+ end
def add_tag_if_not_already_present(tag)
self.tag_string = self.tag_string + " " + tag
end