Class: Cocoadex::Keyword

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoadex/keyword.rb

Constant Summary collapse

CLASS_METHOD_DELIM =
'+'
INST_METHOD_DELIM =
'-'
CLASS_PROP_DELIM =
'.'
SCOPE_CHARS =
[CLASS_PROP_DELIM,CLASS_METHOD_DELIM,INST_METHOD_DELIM]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(term, type, docset, url) ⇒ Keyword

Returns a new instance of Keyword.



30
31
32
# File 'lib/cocoadex/keyword.rb', line 30

def initialize term, type, docset, url
  @term, @type, @docset, @url = term, type, docset, url
end

Instance Attribute Details

#docsetObject (readonly)

Returns the value of attribute docset.



6
7
8
# File 'lib/cocoadex/keyword.rb', line 6

def docset
  @docset
end

#fkObject

Returns the value of attribute fk.



7
8
9
# File 'lib/cocoadex/keyword.rb', line 7

def fk
  @fk
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/cocoadex/keyword.rb', line 7

def id
  @id
end

#termObject (readonly)

Returns the value of attribute term.



6
7
8
# File 'lib/cocoadex/keyword.rb', line 6

def term
  @term
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/cocoadex/keyword.rb', line 6

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/cocoadex/keyword.rb', line 6

def url
  @url
end

Class Method Details

.find(text) ⇒ Object

Search the cache for matching text



15
16
17
18
19
20
21
22
23
24
# File 'lib/cocoadex/keyword.rb', line 15

def self.find text
  logger.debug "Searching tokens for #{text}"
  if scope = Keyword.get_scope(text)
    class_name, term = text.split(scope)
    find_with_scope(scope, class_name, term)
  else
    keys = Tokenizer.fuzzy_match(text)
    keys.map {|k| k.to_element }
  end
end

.get_scope(text) ⇒ Object



26
27
28
# File 'lib/cocoadex/keyword.rb', line 26

def self.get_scope text
  SCOPE_CHARS.detect {|c| text.include? c}
end

Instance Method Details

#inspectObject



38
39
40
# File 'lib/cocoadex/keyword.rb', line 38

def inspect
  "<Keyword:#{type} @term=\"#{term}\">"
end

#to_elementObject



34
35
36
# File 'lib/cocoadex/keyword.rb', line 34

def to_element
  Tokenizer.untokenize([self]).first
end

#to_sObject



42
43
44
# File 'lib/cocoadex/keyword.rb', line 42

def to_s
  "#{type} => #{term}"
end