mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-24 01:36:10 +01:00
Pull out RichMessageExtractor
No need to have it embedded when it should be unit tested!
This commit is contained in:
parent
519e3df4d4
commit
ecdade33c3
3 changed files with 83 additions and 29 deletions
28
app/services/rich_message_extractor.rb
Normal file
28
app/services/rich_message_extractor.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
class RichMessageExtractor
|
||||
|
||||
RICH_MESSAGE_FIELDS_REGEX = /([^>@]*)@?([^>]*)>?(.*)/
|
||||
|
||||
def initialize(message)
|
||||
@message = message
|
||||
end
|
||||
|
||||
def description
|
||||
fields[1].strip
|
||||
end
|
||||
|
||||
def context
|
||||
fields[2].strip
|
||||
end
|
||||
|
||||
def project
|
||||
stripped = fields[3].strip
|
||||
stripped.blank? ? nil : stripped
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fields
|
||||
@message.match(RICH_MESSAGE_FIELDS_REGEX)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,34 +1,5 @@
|
|||
class TodoFromRichMessage
|
||||
|
||||
class RichMessageExtractor
|
||||
|
||||
RICH_MESSAGE_FIELDS_REGEX = /([^>@]*)@?([^>]*)>?(.*)/
|
||||
|
||||
def initialize(message)
|
||||
@message = message
|
||||
end
|
||||
|
||||
def description
|
||||
fields[1].strip
|
||||
end
|
||||
|
||||
def context
|
||||
fields[2].strip
|
||||
end
|
||||
|
||||
def project
|
||||
stripped = fields[3].strip
|
||||
stripped.blank? ? nil : stripped
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fields
|
||||
@message.match(RICH_MESSAGE_FIELDS_REGEX)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
attr_reader :user, :default_context_id, :description, :notes
|
||||
|
||||
def initialize(user, default_context_id, description, notes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue