class Paragraph

Used by LearningDiary Initialized with plain text, will parse and hold tagged content Can keep track of time, section and id information from previous paragraphs using class instance variables

Attributes

id[RW]

The number of paragraph instances instantiated since last reset. Used to seqentially number the instances in a learning diary

end_time[RW]

instance start time and instance end time.

id[R]
start_time[RW]

instance start time and instance end time.

Public Class Methods

new(raw_paragraph_string) click to toggle source

@param [String] raw_paragraph_string a single paragraph from a text file.

# File lib/docfolio/paragraph.rb, line 18
def initialize(raw_paragraph_string)
  @tag_extractor = TagExtractor.new

  extract_content(extract_time(raw_paragraph_string))

  @start_time = TimeProcesser.st
  @end_time = TimeProcesser.et
  @id = Paragraph.id
  Paragraph.id += 1
end
reset() click to toggle source

resets the class variables so that a new file can be parsed is called by LearningDiary when preparing to parse a new txt file

# File lib/docfolio/paragraph.rb, line 31
def self.reset
  TagExtractor.reset
  TimeProcesser.reset
  Paragraph.id = 0
end

Public Instance Methods

[](index) click to toggle source

Implements [] for paragraph @return [Array] an element of the tags array, itself an element

of type [:tag, 'content']
# File lib/docfolio/paragraph.rb, line 45
def [](index)
  tags[index]
end
creditable?() click to toggle source

true if the paragraph contains a tag that can earn credit

# File lib/docfolio/paragraph.rb, line 50
def creditable?
  @tag_extractor.creditable?
end
duration() click to toggle source

public @return [Integer] the interval in minutes between start and end times

# File lib/docfolio/paragraph.rb, line 69
def duration
  return 0 if @end_time.nil? || @start_time.nil?
  (@end_time - @start_time).to_i / 60
end
each(&block) click to toggle source

Iterates through the tags of this paragraph

# File lib/docfolio/paragraph.rb, line 38
def each(&block)
  tags.each { |t| block.call(t) }
end
impact_creditable?() click to toggle source

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

# File lib/docfolio/paragraph.rb, line 55
def impact_creditable?
  @tag_extractor.impact_creditable?
end
significant_event?() click to toggle source
# File lib/docfolio/paragraph.rb, line 63
def significant_event?
  @tag_extractor.significant_event?
end
tag?(tag) click to toggle source
# File lib/docfolio/paragraph.rb, line 59
def tag?(tag)
  @tag_extractor.tag?(tag)
end

Private Instance Methods

all_tags() click to toggle source
# File lib/docfolio/paragraph.rb, line 107
def all_tags
  TagExtractor.all_tags
end
content(tag, str = '') click to toggle source
# File lib/docfolio/paragraph.rb, line 99
def content(tag, str = '')
  @tag_extractor.content(tag, str = '')
end
extract_content(rest_of_str) click to toggle source
# File lib/docfolio/paragraph.rb, line 95
def extract_content(rest_of_str)
  @tag_extractor.extract_content(rest_of_str)
end
extract_time(p) click to toggle source

TimeProcesser.date is a class instance variable that holds the date to apply to this and subsequent paragraphs. It is initialized to nil when the program starts and reset to nil when reset is called (which it is called by the LearningDiary when initializing to parse a new file, called by the Collater when iterating through each text file)

# File lib/docfolio/paragraph.rb, line 81
def extract_time(p)
  # The extract_date function is from the DateExtractor class in the
  # date module
  array = DateExtractor.new.extract_date(p, TimeProcesser.date)
  rest_of_str, time_array, TimeProcesser.date = array

  # Takes the current class instance times and dates and any newly extracted
  # paragraph dates from this paragraph, follows a set of rules to
  # determine what the class instant times and dates should become
  TimeProcesser.new.process_times(time_array)

  rest_of_str
end
method_missing(n, *args, &block) click to toggle source

Acts and a getter and setter for tagged content. Adds a getter and setter methods for each tag with the name of the tag. For example:

paragraph.intro('my intro')

Would and an :INTRO tag with the text content of 'my intro'

paragraph.intro

Returns all content with a tag of :INTRO

Calls superclass method
# File lib/docfolio/paragraph.rb, line 124
def method_missing(n, *args, &block)
  # tag getter
  args[0].nil? && all_tags.include?(n) ? content(n) : super(n, *args, &block)
end
tags() click to toggle source
# File lib/docfolio/paragraph.rb, line 103
def tags
  @tag_extractor.tags
end