Class: RichMessageExtractor
- Inherits:
-
Object
- Object
- RichMessageExtractor
- Extended by:
- ActionView::Helpers::SanitizeHelper::ClassMethods
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- app/services/rich_message_extractor.rb
Constant Summary collapse
- PROJECT_MARKER =
'~'.freeze
- CONTEXT_MARKER =
'@'.freeze
- TICKLER_MARKER =
'>'.freeze
- DUE_MARKER =
'<'.freeze
- TAG_MARKER =
'#'.freeze
- STAR_MARKER =
'*'.freeze
- ALL_MARKERS =
[ PROJECT_MARKER, CONTEXT_MARKER, TICKLER_MARKER, DUE_MARKER, TAG_MARKER, STAR_MARKER ].freeze
Instance Method Summary collapse
- #context ⇒ Object
- #description ⇒ Object
- #due ⇒ Object
- #fix_date_string(yymmdd) ⇒ Object private
-
#initialize(message) ⇒ RichMessageExtractor
constructor
A new instance of RichMessageExtractor.
- #project ⇒ Object
- #select_for(symbol) ⇒ Object private
- #show_from ⇒ Object
- #starred? ⇒ Boolean
- #tags ⇒ Object
Constructor Details
#initialize(message) ⇒ RichMessageExtractor
Returns a new instance of RichMessageExtractor.
22 23 24 |
# File 'app/services/rich_message_extractor.rb', line 22 def initialize() = end |
Instance Method Details
#context ⇒ Object
31 32 33 34 |
# File 'app/services/rich_message_extractor.rb', line 31 def context context = select_for(CONTEXT_MARKER) context.blank? ? '' : sanitize(context[1].strip) end |
#description ⇒ Object
26 27 28 29 |
# File 'app/services/rich_message_extractor.rb', line 26 def description desc = select_for('') desc.blank? ? '' : sanitize(desc[1].strip) end |
#due ⇒ Object
52 53 54 55 |
# File 'app/services/rich_message_extractor.rb', line 52 def due due = select_for DUE_MARKER due.blank? ? nil : Time.zone.parse(fix_date_string(due[1].strip)) end |
#fix_date_string(yymmdd) ⇒ Object (private)
72 73 74 |
# File 'app/services/rich_message_extractor.rb', line 72 def fix_date_string(yymmdd) "20#{yymmdd[0..1]}-#{yymmdd[2..3]}-#{yymmdd[4..5]} 00:00" end |
#project ⇒ Object
36 37 38 39 |
# File 'app/services/rich_message_extractor.rb', line 36 def project project = select_for PROJECT_MARKER project.blank? ? nil : sanitize(project[1].strip) end |
#select_for(symbol) ⇒ Object (private)
68 69 70 |
# File 'app/services/rich_message_extractor.rb', line 68 def select_for(symbol) .match /#{symbol}(.*?)(?=[#{ALL_MARKERS.join}]|\Z)/ end |
#show_from ⇒ Object
57 58 59 60 |
# File 'app/services/rich_message_extractor.rb', line 57 def show_from show_from = select_for TICKLER_MARKER show_from.blank? ? nil : Time.zone.parse(fix_date_string(show_from[1].strip)) end |
#starred? ⇒ Boolean
62 63 64 |
# File 'app/services/rich_message_extractor.rb', line 62 def starred? .include? '*' end |
#tags ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'app/services/rich_message_extractor.rb', line 41 def string = .dup = [] # Regex only matches one tag, so recurse until we have them all while string.match /#(.*?)(?=[#{ALL_MARKERS.join}]|\Z)/ << sanitize($1) string.gsub!(/##{$1}/, '') end .empty? ? nil : end |