Class Tag
In: app/models/tag.rb
Parent: Object

Methods

<=>   []   array_from_s   blog   eql?   from_s   hash   home_page?   main_page   name?   new   peer_group   replace   sandbox   system?   to_s   untagged   user   user_group  

Included Modules

Comparable

Attributes

string  [RW]  Attributes

Public Class methods

Creates an array of link_tag_hashes from a string.

Effectively the syntax here is a chain of valid LinkTag strings seperated by ’/’s.

[Source]

     # File app/models/tag.rb, line 121
121:   def self.array_from_s(tags_string)
122:     if tags_string !~ Const::Tag::CHECK_TAGS_RE
123:       raise ParsingError.new(tags_string), I18n.t('m.tag.error_invalid_tags')
124:     end
125:     tags_array = Array.new
126:     tags_string.split('/').each {|t_s| # extra trailing '/''s are ignored
127:       tags_array.push(Tag.from_s(t_s))
128:     }
129:     return tags_array
130:   end

Returns the blog tag.

[Source]

    # File app/models/tag.rb, line 83
83:   def self.blog
84:     return GlobalConfig.blog_tag
85:   end

Parses a tag from a tag_string.

Syntax: <tag string>

Example: George Bush

[Source]

     # File app/models/tag.rb, line 97
 97:   def self.from_s(tag_string)
 98:     if tag_string !~ Const::Tag::CHECK_TAG_RE
 99:       raise ParsingError.new(tag_string), I18n.t('defaults.error_tag_invalid_string')
100:     end
101:     tag_string = tag_string.dup
102:     # add spaces before upper-case letters in WikiWords
103:     tag_string.gsub!(/([^\s_.])([A-Z][a-z-])/,'\1 \2')
104:     # replace spaces by underscores
105:     tag_string.gsub!(/\s/,'_')
106:     # add capitals after underscores
107:     tag_string.gsub!(/(^|_)(.)/) { $1 + $2.upcase }
108:     if tag_string =~ Const::Tag::RESERVED_WORDS_RE
109:       raise ParsingError.new(tag_string), I18n.t('defaults.error_tag_reserved_words')
110:     end
111:     if tag_string.size > 80
112:       raise ParsingError.new(tag_string), I18n.t('m.tag.error_too_long')
113:     end
114:     return Tag.new(tag_string)
115:   end

Returns the main tag.

[Source]

    # File app/models/tag.rb, line 40
40:   def self.main_page
41:     return GlobalConfig.main_page_tag
42:   end

Initializes with the given string.

No tests or normalisations are applied to the string, so only feed it from the db.

[Source]

    # File app/models/tag.rb, line 30
30:   def initialize(string)
31:     @string = string
32:   end

Returns the peer_group tag.

[Source]

    # File app/models/tag.rb, line 58
58:   def self.peer_group
59:     return GlobalConfig.peer_group_tag
60:   end

Returns the place-holder tag. Used for tag editing when there‘s no real tag.

[Source]

    # File app/models/tag.rb, line 65
65:   def self.replace
66:     return GlobalConfig.replace_tag
67:   end

Returns the sandbox tag. For playing :)

[Source]

    # File app/models/tag.rb, line 77
77:   def self.sandbox
78:     return GlobalConfig.sandbox_tag
79:   end

Returns the untagged tag. Used when the logi is untagged.

[Source]

    # File app/models/tag.rb, line 71
71:   def self.untagged
72:     return GlobalConfig.untagged_tag
73:   end

Returns the user tag.

[Source]

    # File app/models/tag.rb, line 46
46:   def self.user
47:     return GlobalConfig.user_tag
48:   end

Returns the user_group tag.

[Source]

    # File app/models/tag.rb, line 52
52:   def self.user_group
53:     return GlobalConfig.user_group_tag
54:   end

Public Instance methods

Compares two tags and/or strings, based on to_s.

[Source]

     # File app/models/tag.rb, line 142
142:   def <=>(other)
143:     return (self.string <=> other.string)
144:   end

Methods

[Source]

     # File app/models/tag.rb, line 134
134:   def [](var)
135:     return @string.to_s
136:   end

Used in uniq, etc…

[Source]

     # File app/models/tag.rb, line 148
148:   def eql?(other)
149:     self.hash == other.hash
150:   end

Must be equal if object are eql?

[Source]

     # File app/models/tag.rb, line 154
154:   def hash
155:     self.string.hash
156:   end

Returns true if this tag is a user, user_group or peer_group tag.

[Source]

     # File app/models/tag.rb, line 174
174:   def home_page?
175:     return (self == Tag.user or self == Tag.user_group or
176:         self == Tag.peer_group)
177:   end

Returns true if this tag is being used for an user-name or a peergroup-name.

[Source]

     # File app/models/tag.rb, line 161
161:   def name?
162:     if User.find_by_home_page_tag_string(self.string) or
163:         PeerGroup.find_by_home_page_tag_string(self.string) or
164:         UserGroup.find_by_home_page_tag_string(self.string)
165:       return true
166:     else
167:       return false
168:     end
169:   end

Returns true if this tag is a system-tag, like the replace tag (not the home-page).

[Source]

     # File app/models/tag.rb, line 182
182:   def system?
183:     return (self == Tag.replace or self == Tag.untagged or
184:         self == Tag.sandbox)
185:   end

Parses a Tag into a string.

Options

  • :for => :use (default), :show

[Source]

     # File app/models/tag.rb, line 194
194:   def to_s(options = {})
195:     if options[:for] == :show
196:       return self.string.gsub('_', ' ')
197:     else
198:       return self.string
199:     end
200:   end

[Validate]