class Stride::AtlassianDocumentFormatExpander::ContentBlock
Constants
- MENTION_REGEX
- MENTION_REGEX_WITHOUT_GROUPS
Attributes
initial_json[RW]
Public Class Methods
new(initial_json)
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 47 def initialize(initial_json) self.initial_json = initial_json end
Public Instance Methods
as_json()
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 51 def as_json split? ? split_json : initial_json end
Private Instance Methods
match_data()
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 63 def match_data @match_data ||= initial_json['text'].match(MENTION_REGEX) end
mention_at_beginning?()
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 92 def mention_at_beginning? (initial_json['text'] =~ MENTION_REGEX_WITHOUT_GROUPS) == 0 end
mention_block()
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 105 def mention_block @mention_block ||= self.class.new({ "type" => "mention", "attrs" => { "id" => match_data[2], "text" => "@#{match_data[1]}", "accessLevel" => "CONTAINER" } }) end
mention_in_middle?()
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 88 def mention_in_middle? text_blocks_joined_by_mention_block.count > 1 end
split?()
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 59 def split? initial_json.has_key?('text') && match_data.present? end
split_blocks()
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 71 def split_blocks return text_blocks_joined_by_mention_block if mention_in_middle? if mention_at_beginning? text_blocks_joined_by_mention_block.prepend mention_block else text_blocks_joined_by_mention_block << mention_block end end
split_json()
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 67 def split_json split_blocks.map(&:as_json) end
text_blocks()
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 96 def text_blocks @text_blocks ||= initial_json['text'].split(MENTION_REGEX_WITHOUT_GROUPS).map do |text| self.class.new({ "type" => "text", "text" => text }) end end
text_blocks_joined_by_mention_block()
click to toggle source
# File lib/stride/atlassian_document_format_expander.rb, line 81 def text_blocks_joined_by_mention_block @text_blocks_joined_by_mention_block ||= text_blocks.each_with_object([]) do |text_block, all_blocks| all_blocks << text_block all_blocks << mention_block unless text_block == text_blocks.last end.reject { |block| block.as_json['text'] == '' } end