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
The number of paragraph instances instantiated since last reset. Used to seqentially number the instances in a learning diary
instance start time and instance end time.
instance start time and instance end time.
Public Class Methods
@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
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
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
true if the paragraph contains a tag that can earn credit
# File lib/docfolio/paragraph.rb, line 50 def creditable? @tag_extractor.creditable? end
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
Iterates through the tags of this paragraph
# File lib/docfolio/paragraph.rb, line 38 def each(&block) tags.each { |t| block.call(t) } end
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
# File lib/docfolio/paragraph.rb, line 63 def significant_event? @tag_extractor.significant_event? end
# File lib/docfolio/paragraph.rb, line 59 def tag?(tag) @tag_extractor.tag?(tag) end
Private Instance Methods
# File lib/docfolio/paragraph.rb, line 99 def content(tag, str = '') @tag_extractor.content(tag, str = '') end
# File lib/docfolio/paragraph.rb, line 95 def extract_content(rest_of_str) @tag_extractor.extract_content(rest_of_str) end
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
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
# 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