class TaggedContent::TagExtractor
Constants
- CREDITABLE
Tags that can earn CPD credit
- LEARNING_LOG
Tags that are used in learning logs
- SECTIONS
Tags that are applied to content based on the position in the document
- SIG_EVENT
Tags that are used in significant events
- TAGS
Tags that are part of the DSL and are recognized in text
Attributes
Public Class Methods
# File lib/docfolio/paragraph_modules/tags.rb, line 8 def initialize @tags = [] end
resets the class variables so that a new file can be parsed is called by LearningDiary
(through Paragraph
) when preparing to parse a new txt file
# File lib/docfolio/paragraph_modules/tags.rb, line 22 def self.reset TagExtractor.section = 0 # :TITLE end
Public Instance Methods
Joins all content in @tags of with a tag of type tag @param [Symbol] tag The tag for which content that should be selected. @param [String] str An optional string that can be passed to the function
to which selected content will be appended.
# File lib/docfolio/paragraph_modules/tags.rb, line 59 def content(tag, str = '') tag_index = 0 content_index = 1 @tags.each { |t| str << t[content_index] + ' ' if t[tag_index] == tag } str end
true if the paragraph contains a tag that can earn credit
# File lib/docfolio/paragraph_modules/tags.rb, line 67 def creditable? tags.each { |t| return true if CREDITABLE.include?(t[0]) } false end
# File lib/docfolio/paragraph_modules/tags.rb, line 30 def extract_content(rest_of_str) # if a new date or time has not been found then return return if rest_of_str == '' @old_tags = @tags @tags += extract_tags(rest_of_str) if tags_extracted? # As soon as tags are extracted, there can only be note internal # paragraph sections TagExtractor.section = 2 #:NOTE else # No tags have been extracted from the str, so use the paragraphs # current section tag_as_section(rest_of_str) end end
true if the paragraph contains a tag that can earn impact credit
# File lib/docfolio/paragraph_modules/tags.rb, line 80 def impact_creditable? tags.each { |t| return true if t[0] == :I } false end
true if the paragraph contains a tag used in significant events i.e. is the learning diary a significant event?
# File lib/docfolio/paragraph_modules/tags.rb, line 74 def significant_event? tags.each { |t| return true if SIG_EVENT.include?(t[0]) } false end
returns true if any tags are of type tag @param [Array] tag An array of tags
# File lib/docfolio/paragraph_modules/tags.rb, line 50 def tag?(tag) @tags.each { |t| return true if t[0] == tag } false end
Private Instance Methods
Splits the paragraph into an array of tags of type [:tag, 'content'] @param [String] paragraph_text String text of the paragraph with any
date and time info at the beginning, removed
@return [Array] Tagged array of content with elements of type
[:tag, 'content']
# File lib/docfolio/paragraph_modules/tags.rb, line 170 def extract_tag(paragraph_text) a = paragraph_text.split(tag_regex) preface_with_note(a) + tags_array(a) end
Paragraphs are broken down into a tagged array, with elements of type [:tag, 'text']. The first element of an array is of type string. If the paragraph begins with text before any tags, then this first element will contain this text, otherwise it will be an empty string. This function tests this string and returns it tagged as :NOTE unless empty in which case it returns an empty array [] @param [Array] a An array of tagged content of the paragraph @return [Array] Another tagged array which is either empty, or just
contains a single tagged content of the text at the beginning if there was any.
# File lib/docfolio/paragraph_modules/tags.rb, line 142 def preface_with_note(a) str = a[0].strip str == '' ? [] : [[:NOTE, str]] end
# File lib/docfolio/paragraph_modules/tags.rb, line 190 def section_tag SECTIONS[TagExtractor.section] end
Add a single tagged content element of type
- :symbol (tag), String (content)
-
to the @tags instance instance variable
using the current value of the section class instance variable as an index to reference the correct section tag symbol from the SECTIONS
array. Does not tags content identified in the TAGS
array. @param [String] str the content to tag
# File lib/docfolio/paragraph_modules/tags.rb, line 186 def tag_as_section(str) tag_it(section_tag, str) end
Add a single tagged content element of type
- :symbol (tag), String (content)
-
to the @tags instance instance variable
. Move the section class instance variable up one (to current :INTRO) if it is at position 0 (currently :TITLE) @param [String] p the content to tag @param [Symbol] tag the tag to use
# File lib/docfolio/paragraph_modules/tags.rb, line 118 def tag_it(tag, p) @tags << [tag, p] if TagExtractor.section == 0 && TagExtractor.section != (SECTIONS.count - 1) TagExtractor.section += 1 end end
Creates a regex that can be used to match for tags that are recognized as part of the DSL, currently :LP, :R, :DEN, :NOTE and :I
# File lib/docfolio/paragraph_modules/tags.rb, line 128 def tag_regex /\b(#{ TAGS.join '|' }): ?/ end