Class Context
In: app/models/context.rb
Parent: Object

This class is used to keep track of the current location of the User.

A User can only visit one Logi at a time.

Methods

Included Modules

CacheMethodsModule

Attributes

context_link  [R] 
force  [RW]  Relationships
link  [R] 
query  [R] 
query  [RW]  Relationships
replace_tag  [RW]  Relationships

Public Class methods

Returns the unique tag-sets from the given logis

[Source]

    # File app/models/context.rb, line 53
53:   def self.extract_tag_set_links(logis)
54:     tag_sets = logis.collect {|i| i.tags }.uniq
55:     tag_set_links = tag_sets.collect {|t_s| Link.new(:requested_tags => t_s)}
56:     return tag_set_links.sort
57:   end

Sets the link, required as an option.

[Source]

    # File app/models/context.rb, line 38
38:   def initialize(query_string, options = {})
39:     self.force = options[:force] 
40:     self.replace_tag = options[:replace_tag]
41:     if query_string and !query_string.empty?
42:       # force and replace_tag need to be set before link
43:       self.link = Link.new_from_s(query_string.dup)
44:       self.query = query_string
45:     end
46:     return self
47:   end

Public Instance methods

Cached.

[Source]

     # File app/models/context.rb, line 190
190:   def contending_logis
191:     return self.context_link.volatile_to_logis
192:   end

Returns logis matching all the tags in their given order.

[Source]

     # File app/models/context.rb, line 133
133:   def exact_matching_logis
134:     if self.context_link.exact_match?
135:       return self.context_link.volatile_to_logis
136:     else
137:       return []
138:     end
139:   end

Cached.

[Source]

     # File app/models/context.rb, line 121
121:   def incoming_links_to_logi
122:     if self.link.found_logi?
123:       return self.link.volatile_to_logi.link_matches.collect {|m| m.link}
124:     else
125:       return []
126:     end
127:   end

Cached.

[Source]

     # File app/models/context.rb, line 113
113:   def incoming_links_to_tags
114:     tag_set = self.context_link.requested_tags.sort
115:     query = 'tag_set:__' + tag_set.collect {|t| t.to_s}.join('__').downcase + '__'
116:     return (LogiLogiXapian.search([Link], query) || [])
117:   end

Link-setter.

[Source]

    # File app/models/context.rb, line 65
65:   def link=(link)
66:     if self.replace_tag and
67:         link.requested_tags[0] == self.replace_tag and
68:         link.requested_tags.size == 1
69:       if link.to_logi
70:         link = Link.new_from_s(link.to_logi.to_s)
71:       else
72:         link = nil
73:       end
74:     end
75:     if link
76:       @link = link
77:       @link.resolve(:force => self.force)
78:       if @link.to_logi
79:         # only needs tags for context_link
80:         @context_link = @link.unresolved_dup(:step => -1)
81:         @context_link.resolve(:force => self.force)
82:       else
83:         @context_link = @link
84:       end
85:     end
86:     reset_methods_cache
87:   end

Returns true if there is any match.

[Source]

     # File app/models/context.rb, line 184
184:   def link?
185:     return !self.link.nil?
186:   end

Returns true if there is any match.

[Source]

     # File app/models/context.rb, line 171
171:   def matches?
172:     return ((self.link? and self.link.found_logi?) or
173:         (self.tags? and !self.context_link.volatile_all_logis.empty?))
174:   end

Query setter, requires link to be set.

[Source]

    # File app/models/context.rb, line 91
91:   def query=(query_string)
92:     @query = query_string.split('/').join(' AND ')
93:   end

Formats the query for passing on in urls.

[Source]

    # File app/models/context.rb, line 97
97:   def query_for_url
98:     return @query.split(' AND ').join('/')
99:   end

Returns logis matching the biggest subset of tags (stepping down from their given order, tags themselves in any order) for which logis can be found.

[Source]

     # File app/models/context.rb, line 161
161:   def reduced_matching_logis
162:     if !self.context_link.unreduced_match?
163:       return self.context_link.volatile_all_logis
164:     else
165:       return []
166:     end
167:   end

Returns the unreduced_matching_logis minus the exact_matching_logis.

[Source]

     # File app/models/context.rb, line 153
153:   def sloppy_matching_logis
154:     return self.unreduced_matching_logis - self.exact_matching_logis
155:   end

Cached.

[Source]

     # File app/models/context.rb, line 202
202:   def suggested_tags
203:     if self.context_link.unreduced_match?
204:       tags = []
205:       self.context_link.volatile_all_logis.each do |logi|
206:         tags.concat(logi.tags)
207:       end
208:       haves = self.context_link.received_tags
209:       tags.uniq!
210:       haves.each do |h_t|
211:         tags.delete(h_t)
212:       end
213:       return tags
214:     else
215:       return []
216:     end
217:   end

[Source]

     # File app/models/context.rb, line 194
194:   def suggested_used_tags(options = {})
195:     limit = (options[:limit] || -1)
196:     return self.suggested_tags[0..limit].collect {|t| 
197:         UsedTag.or_new_from_tag(t)}.sort_by {|used_tag| used_tag.tag}
198:   end

Returns the tag-sets for which logis are found

[Source]

     # File app/models/context.rb, line 105
105:   def tag_set_links
106:     return Context.extract_tag_set_links(self.context_link.volatile_all_logis)
107:   end

Returns true if there is any match.

[Source]

     # File app/models/context.rb, line 178
178:   def tags?
179:     return !self.context_link.nil?
180:   end

Returns logis matching all the tags in any order.

[Source]

     # File app/models/context.rb, line 143
143:   def unreduced_matching_logis
144:     if self.context_link.unreduced_match?
145:       return self.context_link.volatile_all_logis
146:     else
147:       return []
148:     end
149:   end

[Validate]