Class: Taggata::Parser::Tag
- Inherits:
-
Object
- Object
- Taggata::Parser::Tag
- Defined in:
- lib/taggata/parser/tag.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
-
#initialize(db) ⇒ Tag
constructor
A new instance of Tag.
-
#parse(query) ⇒ Hash
Parses give tagging string.
Constructor Details
#initialize(db) ⇒ Tag
Returns a new instance of Tag.
7 8 9 |
# File 'lib/taggata/parser/tag.rb', line 7 def initialize(db) @db = db end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
5 6 7 |
# File 'lib/taggata/parser/tag.rb', line 5 def db @db end |
Instance Method Details
#parse(query) ⇒ Hash
Parses give tagging string
15 16 17 18 19 20 21 22 23 |
# File 'lib/taggata/parser/tag.rb', line 15 def parse(query) result = { :add => [], :del => [] } hash = query.split.reduce(result) do |acc, tag| handle_tag(tag, acc) end dels = hash[:del].empty? ? [] : ::Taggata::Persistent::Tag.find(db, :name => hash[:del]) adds = hash[:add].empty? ? [] : (hash[:add]) { :add => adds, :del => dels } end |