Class: Pebbles::Uid::Query
- Inherits:
-
Object
- Object
- Pebbles::Uid::Query
- Defined in:
- lib/pebbles-uid/query.rb
Constant Summary collapse
- NO_MARKER =
Class.new
Instance Attribute Summary collapse
-
#oid ⇒ Object
readonly
Returns the value of attribute oid.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#path_name ⇒ Object
readonly
Returns the value of attribute path_name.
-
#species ⇒ Object
readonly
Returns the value of attribute species.
-
#species_name ⇒ Object
readonly
Returns the value of attribute species_name.
-
#stop ⇒ Object
readonly
Returns the value of attribute stop.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
-
#term ⇒ Object
readonly
Returns the value of attribute term.
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
Instance Method Summary collapse
- #cache_keys ⇒ Object
- #collection? ⇒ Boolean
- #epiteth ⇒ Object
- #epiteth? ⇒ Boolean
- #for_one? ⇒ Boolean
- #genus ⇒ Object
-
#initialize(term, options = {}) ⇒ Query
constructor
A new instance of Query.
- #list ⇒ Object
- #list? ⇒ Boolean
- #next_path_label ⇒ Object
- #oid? ⇒ Boolean
- #path? ⇒ Boolean
- #species? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(term, options = {}) ⇒ Query
Returns a new instance of Query.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pebbles-uid/query.rb', line 11 def initialize(term, = {}) @term = term @species_name = .fetch(:species) { 'species' } @path_name = .fetch(:path) { 'path' } @suffix = [:suffix] @stop = .fetch(:stop) { NO_MARKER } if multi_oid_query? @terms = (term) elsif wildcard_query? @terms = [term] else @terms = extract_terms end if list? @species, @path, _ = Pebbles::Uid.parse(terms.first) else @species, @path, @oid = Pebbles::Uid.parse(term) end end |
Instance Attribute Details
#oid ⇒ Object (readonly)
Returns the value of attribute oid.
9 10 11 |
# File 'lib/pebbles-uid/query.rb', line 9 def oid @oid end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/pebbles-uid/query.rb', line 9 def path @path end |
#path_name ⇒ Object (readonly)
Returns the value of attribute path_name.
9 10 11 |
# File 'lib/pebbles-uid/query.rb', line 9 def path_name @path_name end |
#species ⇒ Object (readonly)
Returns the value of attribute species.
9 10 11 |
# File 'lib/pebbles-uid/query.rb', line 9 def species @species end |
#species_name ⇒ Object (readonly)
Returns the value of attribute species_name.
9 10 11 |
# File 'lib/pebbles-uid/query.rb', line 9 def species_name @species_name end |
#stop ⇒ Object (readonly)
Returns the value of attribute stop.
9 10 11 |
# File 'lib/pebbles-uid/query.rb', line 9 def stop @stop end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
9 10 11 |
# File 'lib/pebbles-uid/query.rb', line 9 def suffix @suffix end |
#term ⇒ Object (readonly)
Returns the value of attribute term.
9 10 11 |
# File 'lib/pebbles-uid/query.rb', line 9 def term @term end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
9 10 11 |
# File 'lib/pebbles-uid/query.rb', line 9 def terms @terms end |
Instance Method Details
#cache_keys ⇒ Object
76 77 78 |
# File 'lib/pebbles-uid/query.rb', line 76 def cache_keys terms.map { |t| Pebbles::Uid.cache_key(t) } end |
#collection? ⇒ Boolean
48 49 50 |
# File 'lib/pebbles-uid/query.rb', line 48 def collection? !for_one? && !list? end |
#epiteth ⇒ Object
68 69 70 |
# File 'lib/pebbles-uid/query.rb', line 68 def epiteth species_wrapper.tail.join('.') end |
#epiteth? ⇒ Boolean
60 61 62 |
# File 'lib/pebbles-uid/query.rb', line 60 def epiteth? !species_wrapper.tail.empty? end |
#for_one? ⇒ Boolean
33 34 35 |
# File 'lib/pebbles-uid/query.rb', line 33 def for_one? oid? end |
#genus ⇒ Object
64 65 66 |
# File 'lib/pebbles-uid/query.rb', line 64 def genus species.split('.').first end |
#list ⇒ Object
41 42 43 44 45 46 |
# File 'lib/pebbles-uid/query.rb', line 41 def list if !list? raise "Cannot expand non-list query" end terms end |
#list? ⇒ Boolean
37 38 39 |
# File 'lib/pebbles-uid/query.rb', line 37 def list? terms.size != 1 or %w(, |).include?(term.strip[-1..-1]) end |
#next_path_label ⇒ Object
93 94 95 |
# File 'lib/pebbles-uid/query.rb', line 93 def next_path_label path_wrapper.next_label end |
#oid? ⇒ Boolean
72 73 74 |
# File 'lib/pebbles-uid/query.rb', line 72 def oid? !!@oid && @oid != '*' end |
#path? ⇒ Boolean
52 53 54 |
# File 'lib/pebbles-uid/query.rb', line 52 def path? @path && @path.split('.').reject {|s| s == '*'}.length > 0 end |
#species? ⇒ Boolean
56 57 58 |
# File 'lib/pebbles-uid/query.rb', line 56 def species? @species && @species != '*' end |
#to_hash ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pebbles-uid/query.rb', line 80 def to_hash if list? raise RuntimeError.new('Cannot compute a conditions hash for a list of uids') end hash = species_wrapper.to_hash.merge(path_wrapper.to_hash) if oid? oid_key = ['oid', suffix].compact.join('_').to_sym hash = hash.merge(oid_key => oid) end hash end |