Class: TaggedContent::TagExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/docfolio/paragraph_modules/tags.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTagExtractor

Returns a new instance of TagExtractor.



8
9
10
# File 'lib/docfolio/paragraph_modules/tags.rb', line 8

def initialize
  @tags =  []
end

Class Attribute Details

.sectionObject

Returns the value of attribute section.



16
17
18
# File 'lib/docfolio/paragraph_modules/tags.rb', line 16

def section
  @section
end

Instance Attribute Details

#tagsObject (readonly)

Returns the value of attribute tags.



6
7
8
# File 'lib/docfolio/paragraph_modules/tags.rb', line 6

def tags
  @tags
end

Class Method Details

.all_tagsObject



26
27
28
# File 'lib/docfolio/paragraph_modules/tags.rb', line 26

def self.all_tags
  SECTIONS + TAGS
end

.resetObject

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



22
23
24
# File 'lib/docfolio/paragraph_modules/tags.rb', line 22

def self.reset
  TagExtractor.section = 0 # :TITLE
end

Instance Method Details

#content(tag, str = '') ⇒ Object

Joins all content in @tags of with a tag of type tag

Parameters:

  • tag (Symbol)

    The tag for which content that should be selected.

  • str (String) (defaults to: '')

    An optional string that can be passed to the function to which selected content will be appended.



59
60
61
62
63
64
# 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

#creditable?Boolean

true if the paragraph contains a tag that can earn credit

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/docfolio/paragraph_modules/tags.rb', line 67

def creditable?
  tags.each { |t| return true if CREDITABLE.include?(t[0]) }
  false
end

#extract_content(rest_of_str) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

#impact_creditable?Boolean

true if the paragraph contains a tag that can earn impact credit

Returns:

  • (Boolean)


80
81
82
83
# File 'lib/docfolio/paragraph_modules/tags.rb', line 80

def impact_creditable?
  tags.each { |t| return true if t[0] == :I }
  false
end

#significant_event?Boolean

true if the paragraph contains a tag used in significant events i.e. is the learning diary a significant event?

Returns:

  • (Boolean)


74
75
76
77
# 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

#tag?(tag) ⇒ Boolean

returns true if any tags are of type tag

Parameters:

  • tag (Array)

    An array of tags

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/docfolio/paragraph_modules/tags.rb', line 50

def tag?(tag)
  @tags.each { |t| return true if t[0] == tag }
  false
end