Class: Paragraph

Inherits:
Object
  • Object
show all
Includes:
DateTimes, TaggedContent
Defined in:
lib/docfolio/paragraph.rb

Overview

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_paragraph_string) ⇒ Paragraph

Returns a new instance of Paragraph.

Parameters:

  • raw_paragraph_string (String)

    a single paragraph from a text file.



18
19
20
21
22
23
24
25
26
27
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(n, *args, &block) ⇒ Object (private)

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



124
125
126
127
# 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

Class Attribute Details

.idObject

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



115
116
117
# File 'lib/docfolio/paragraph.rb', line 115

def id
  @id
end

Instance Attribute Details

#end_timeObject

instance start time and instance end time.



15
16
17
# File 'lib/docfolio/paragraph.rb', line 15

def end_time
  @end_time
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/docfolio/paragraph.rb', line 12

def id
  @id
end

#start_timeObject

instance start time and instance end time.



15
16
17
# File 'lib/docfolio/paragraph.rb', line 15

def start_time
  @start_time
end

Class Method Details

.resetObject

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



31
32
33
34
35
# File 'lib/docfolio/paragraph.rb', line 31

def self.reset
  TagExtractor.reset
  TimeProcesser.reset
  Paragraph.id = 0
end

Instance Method Details

#[](index) ⇒ Array

Implements [] for paragraph

Returns:

  • (Array)

    an element of the tags array, itself an element of type [:tag, ‘content’]



45
46
47
# File 'lib/docfolio/paragraph.rb', line 45

def [](index)
  tags[index]
end

#creditable?Boolean

true if the paragraph contains a tag that can earn credit

Returns:

  • (Boolean)


50
51
52
# File 'lib/docfolio/paragraph.rb', line 50

def creditable?
  @tag_extractor.creditable?
end

#durationInteger

public

Returns:

  • (Integer)

    the interval in minutes between start and end times



69
70
71
72
# 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) ⇒ Object

Iterates through the tags of this paragraph



38
39
40
# File 'lib/docfolio/paragraph.rb', line 38

def each(&block)
  tags.each { |t| block.call(t) }
end

#impact_creditable?Boolean

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

Returns:

  • (Boolean)


55
56
57
# File 'lib/docfolio/paragraph.rb', line 55

def impact_creditable?
  @tag_extractor.impact_creditable?
end

#significant_event?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/docfolio/paragraph.rb', line 63

def significant_event?
  @tag_extractor.significant_event?
end

#tag?(tag) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/docfolio/paragraph.rb', line 59

def tag?(tag)
  @tag_extractor.tag?(tag)
end