class ActsAsTaggableOnMongoid::GenericParser
Returns a new list of tags (array of strings) using the given tag string.
Example: tag_list = ActsAsTaggableOn::GenericParser.new.parse(“One , Two, Three”) tag_list # [“One ”, “ Two”, “ Three”]
All parsers are required to support two methods:
* parse - parse the tag_list into an array of strings * to_s - return a parsed array of tags (may be passed in parsed) in a format that is suitable for parsing. NOTE: The ablitity to parse a list of tags and convert it to a string then back to the same list of tags is dependent on the complexity of the parser. This is not actually assumed to be true, though it is best if it is.
Cleansing the list of tags for the tag is the responsibility of the tags TagList
which knows if the tags need to be stripped, downcased, etc. The parser need only return an array of strings that are split out.
Constants
- DEFAULT_DELIMITER
Attributes
Public Class Methods
new(*tag_list)
click to toggle source
# File lib/acts_as_taggable_on_mongoid/generic_parser.rb, line 28 def initialize(*tag_list) @tags = tag_list.flatten end
Public Instance Methods
parse()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/generic_parser.rb, line 32 def parse @tags = [].tap do |tag_list| tags.each do |tag| tag_list.concat tag.split(DEFAULT_DELIMITER).map(&:strip).reject(&:empty?) end end.flatten end
to_s()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/generic_parser.rb, line 40 def to_s tags.join(DEFAULT_DELIMITER) end