Module: Rtasklib::Helpers
Overview
A collection of stateless, non-end-user facing functions available throughout the library
Instance Method Summary collapse
-
#arbitrary_attr(attr, depth: 1) ⇒ Boolean
Returns part of attribute at a given depth.
-
#deep_attr(attr, depth: 2) ⇒ Boolean
Returns all attribute string after given depth.
-
#determine_type(value) ⇒ Axiom::Types::Boolean, ...
Determine the type that a value should be coerced to Int needs to precede float because ints are also floats Doesn’t detect arrays, b/c task stores these as comma separated strings which could just as easily be Strings.…
-
#filter(ids: nil, tags: nil, dom: nil) ⇒ String
Converts ids, tags, and dom queries to a single string ready to pass directly to task.
-
#id_a_to_s(id_a) ⇒ String
Filters should be a list of values Ranges interpreted as ids 1…5 : “1,2,3,4,5” 1..5 : “1,2,3,4” 1 : “1” and joined with “,” [1…5, 8, 9] : “1,2,3,4,5,8,9”.
-
#id_range_to_s(id_range) ⇒ Array<String>
Convert a range to a comma separated strings, e.g.
-
#pending_or_waiting(use = true) ⇒ String
Returns a “+PENDING or +WAITING” tag string if true, else “”.
-
#process_dom(dom) ⇒ Object
Process string and array input of the likes of project:Work or description.contains:yolo.
-
#process_hash_dom(dom_hash) ⇒ String
Parse the hash input to a string.
-
#process_ids(ids) ⇒ Object
Converts arbitrary id input to a task safe string.
-
#process_tag(tag) ⇒ String
Ensures that a tag begins with a + or -.
-
#process_tags(tags) ⇒ Object
private
Convert a tag string or an array of strings to a space separated string.
-
#to_gem_version(raw) ⇒ Gem::Version
Converts a string of format “1.6.2 (adf342jsd)” to Gem::Version object.
-
#uda_attr?(attr) ⇒ Boolean
Is a given taskrc attribute dealing with udas?.
-
#wrap_string(string) ⇒ Object
Wrap a string with quotes to make it safe to pass to
task.
Instance Method Details
#arbitrary_attr(attr, depth: 1) ⇒ Boolean
Returns part of attribute at a given depth
147 148 149 |
# File 'lib/rtasklib/helpers.rb', line 147 def arbitrary_attr attr, depth: 1 attr.to_s.split("_")[depth] end |
#deep_attr(attr, depth: 2) ⇒ Boolean
Returns all attribute string after given depth
157 158 159 |
# File 'lib/rtasklib/helpers.rb', line 157 def deep_attr attr, depth: 2 attr.to_s.split("_")[depth..-1].join("_") end |
#determine_type(value) ⇒ Axiom::Types::Boolean, ...
Determine the type that a value should be coerced to Int needs to precede float because ints are also floats Doesn’t detect arrays, b/c task stores these as comma separated strings which could just as easily be Strings.… If nothing works it defaults to String. TODO: JSON parse
194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/rtasklib/helpers.rb', line 194 def determine_type value if boolean? value return Axiom::Types::Boolean elsif integer? value return Integer elsif float? value return Float elsif json? value return MultiJson else return String end end |
#filter(ids: nil, tags: nil, dom: nil) ⇒ String
Converts ids, tags, and dom queries to a single string ready to pass directly to task.
28 29 30 31 32 33 34 |
# File 'lib/rtasklib/helpers.rb', line 28 def filter ids: nil, tags: nil, dom: nil id_s = tag_s = dom_s = "" id_s = process_ids(ids) unless ids.nil? tag_s = () unless .nil? dom_s = process_dom(dom) unless dom.nil? return "#{id_s} #{tag_s} #{dom_s}".strip end |
#id_a_to_s(id_a) ⇒ String
Filters should be a list of values Ranges interpreted as ids 1…5 : “1,2,3,4,5” 1..5 : “1,2,3,4” 1 : “1” and joined with “,”
- 1…5, 8, 9
-
: “1,2,3,4,5,8,9”
47 48 49 50 51 52 |
# File 'lib/rtasklib/helpers.rb', line 47 def id_a_to_s id_a id_a.map do |el| proc_ids = process_ids(el) proc_ids end.compact.join(",") end |
#id_range_to_s(id_range) ⇒ Array<String>
Convert a range to a comma separated strings, e.g. 1..4 -> “1,2,3,4”
76 77 78 |
# File 'lib/rtasklib/helpers.rb', line 76 def id_range_to_s id_range id_range.to_a.join(",") end |
#pending_or_waiting(use = true) ⇒ String
Returns a “+PENDING or +WAITING” tag string if true, else “”
176 177 178 179 180 181 182 |
# File 'lib/rtasklib/helpers.rb', line 176 def pending_or_waiting use=true if use "+PENDING or +WAITING" else "" end end |
#process_dom(dom) ⇒ Object
Process string and array input of the likes of project:Work or description.contains:yolo
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rtasklib/helpers.rb', line 112 def process_dom dom case dom when String dom when Array dom.join(" ") when Hash process_hash_dom(dom) end end |
#process_hash_dom(dom_hash) ⇒ String
Parse the hash input to a string
128 129 130 |
# File 'lib/rtasklib/helpers.rb', line 128 def process_hash_dom dom_hash dom_hash.reduce("") { |dom, (k,v)| dom += "#{k.to_s}:#{v} " }.strip end |
#process_ids(ids) ⇒ Object
Converts arbitrary id input to a task safe string
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rtasklib/helpers.rb', line 58 def process_ids ids case ids when Range return id_range_to_s(ids) when Array return id_a_to_s(ids) when String return ids.delete(" ") when Fixnum return ids end end |
#process_tag(tag) ⇒ String
Ensures that a tag begins with a + or -
97 98 99 100 101 102 103 104 105 |
# File 'lib/rtasklib/helpers.rb', line 97 def process_tag tag reserved_symbols = %w{+ - and or xor < <= = != >= > ( )} # convert plain tags to plus tags unless tag.start_with?(*reserved_symbols) tag = "+#{tag}" end return tag end |
#process_tags(tags) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convert a tag string or an array of strings to a space separated string
84 85 86 87 88 89 90 91 |
# File 'lib/rtasklib/helpers.rb', line 84 def case when String .split(" ").map { |t| process_tag t }.join(" ") when Array .map { |t| t }.join(" ") end end |
#to_gem_version(raw) ⇒ Gem::Version
Converts a string of format “1.6.2 (adf342jsd)” to Gem::Version object
166 167 168 169 |
# File 'lib/rtasklib/helpers.rb', line 166 def to_gem_version raw std_ver = raw.chomp.gsub(' ','.').delete('(').delete(')') Gem::Version.new std_ver end |
#uda_attr?(attr) ⇒ Boolean
Is a given taskrc attribute dealing with udas?
137 138 139 |
# File 'lib/rtasklib/helpers.rb', line 137 def uda_attr? attr attr.to_s.start_with? "uda" end |
#wrap_string(string) ⇒ Object
Wrap a string with quotes to make it safe to pass to task
16 17 18 |
# File 'lib/rtasklib/helpers.rb', line 16 def wrap_string string "\"#{string.to_s}\"" end |