Class: Cocoadex::Keyword
- Inherits:
-
Object
- Object
- Cocoadex::Keyword
- 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
-
#docset ⇒ Object
readonly
Returns the value of attribute docset.
-
#fk ⇒ Object
Returns the value of attribute fk.
-
#id ⇒ Object
Returns the value of attribute id.
-
#term ⇒ Object
readonly
Returns the value of attribute term.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.find(text) ⇒ Object
Search the cache for matching text.
- .get_scope(text) ⇒ Object
Instance Method Summary collapse
-
#initialize(term, type, docset, url) ⇒ Keyword
constructor
A new instance of Keyword.
- #inspect ⇒ Object
- #to_element ⇒ Object
- #to_s ⇒ Object
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
#docset ⇒ Object (readonly)
Returns the value of attribute docset.
6 7 8 |
# File 'lib/cocoadex/keyword.rb', line 6 def docset @docset end |
#fk ⇒ Object
Returns the value of attribute fk.
7 8 9 |
# File 'lib/cocoadex/keyword.rb', line 7 def fk @fk end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/cocoadex/keyword.rb', line 7 def id @id end |
#term ⇒ Object (readonly)
Returns the value of attribute term.
6 7 8 |
# File 'lib/cocoadex/keyword.rb', line 6 def term @term end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/cocoadex/keyword.rb', line 6 def type @type end |
#url ⇒ Object (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
#inspect ⇒ Object
38 39 40 |
# File 'lib/cocoadex/keyword.rb', line 38 def inspect "<Keyword:#{type} @term=\"#{term}\">" end |
#to_element ⇒ Object
34 35 36 |
# File 'lib/cocoadex/keyword.rb', line 34 def to_element Tokenizer.untokenize([self]).first end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/cocoadex/keyword.rb', line 42 def to_s "#{type} => #{term}" end |