Module: TafHelper
- Defined in:
- lib/taf/taf_helper.rb
Constant Summary collapse
- DEFAULT_TAG =
"Untagged".freeze
Class Method Summary collapse
-
.parse_message(message) ⇒ Object
Extracts text, tag, and parent_id from message Returns [text, tag, parent_id] - If @ID (numeric): parent_id is set, tag is nil - If @tag (alphanumeric): tag is set, parent_id is nil - Otherwise: both nil.
-
.parse_tag_or_parent(text, tag_string) ⇒ Object
Determines if tag_string is a parent ID or a tag.
-
.tag_name(tag) ⇒ Object
Transforms ‘@tag-name` to `Tag Name`.
Class Method Details
.parse_message(message) ⇒ Object
Extracts text, tag, and parent_id from message Returns [text, tag, parent_id]
-
If @ID (numeric): parent_id is set, tag is nil
-
If @tag (alphanumeric): tag is set, parent_id is nil
-
Otherwise: both nil
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/taf/taf_helper.rb', line 9 def self.() return [nil, nil, nil] if .to_s.empty? if (tag_only = [/^@[A-Za-z0-9][A-Za-z0-9_-]*$/]) return parse_tag_or_parent(nil, tag_only) end tag = [/ @[A-Za-z0-9][A-Za-z0-9_-]*$/] if tag text = .sub(/ @[A-Za-z0-9][A-Za-z0-9_-]*$/, "") text.strip! parse_tag_or_parent(text, tag) else text = .strip [text, nil, nil] end end |
.parse_tag_or_parent(text, tag_string) ⇒ Object
Determines if tag_string is a parent ID or a tag
28 29 30 31 32 33 34 35 36 |
# File 'lib/taf/taf_helper.rb', line 28 def self.parse_tag_or_parent(text, tag_string) cleaned = tag_string.strip.delete_prefix("@") if cleaned.match?(/^\d+$/) [text, nil, cleaned.to_i] else [text, tag_name(tag_string), nil] end end |
.tag_name(tag) ⇒ Object
Transforms ‘@tag-name` to `Tag Name`
39 40 41 42 43 44 45 46 |
# File 'lib/taf/taf_helper.rb', line 39 def self.tag_name(tag) tag .strip .delete_prefix("@") .split(/[-_]/) .map(&:capitalize) .join(" ") end |