Class: Paragraph
- Inherits:
-
Object
- Object
- Paragraph
- 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
-
.id ⇒ Object
The number of paragraph instances instantiated since last reset.
Instance Attribute Summary collapse
-
#end_time ⇒ Object
instance start time and instance end time.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#start_time ⇒ Object
instance start time and instance end time.
Class Method Summary collapse
-
.reset ⇒ Object
resets the class variables so that a new file can be parsed is called by LearningDiary when preparing to parse a new txt file.
Instance Method Summary collapse
-
#[](index) ⇒ Array
Implements [] for paragraph.
-
#creditable? ⇒ Boolean
true if the paragraph contains a tag that can earn credit.
-
#duration ⇒ Integer
public.
-
#each(&block) ⇒ Object
Iterates through the tags of this paragraph.
-
#impact_creditable? ⇒ Boolean
true if the paragraph contains a tag that can earn impact credit.
-
#initialize(raw_paragraph_string) ⇒ Paragraph
constructor
A new instance of Paragraph.
- #significant_event? ⇒ Boolean
- #tag?(tag) ⇒ Boolean
Constructor Details
#initialize(raw_paragraph_string) ⇒ Paragraph
Returns a new instance of Paragraph.
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? && .include?(n) ? content(n) : super(n, *args, &block) end |
Class Attribute Details
.id ⇒ Object
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_time ⇒ Object
instance start time and instance end time.
15 16 17 |
# File 'lib/docfolio/paragraph.rb', line 15 def end_time @end_time end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/docfolio/paragraph.rb', line 12 def id @id end |
#start_time ⇒ Object
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
.reset ⇒ Object
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
45 46 47 |
# File 'lib/docfolio/paragraph.rb', line 45 def [](index) [index] end |
#creditable? ⇒ Boolean
true if the paragraph contains a tag that can earn credit
50 51 52 |
# File 'lib/docfolio/paragraph.rb', line 50 def creditable? @tag_extractor.creditable? end |
#duration ⇒ Integer
public
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) .each { |t| block.call(t) } end |
#impact_creditable? ⇒ Boolean
true if the paragraph contains a tag that can earn impact credit
55 56 57 |
# File 'lib/docfolio/paragraph.rb', line 55 def impact_creditable? @tag_extractor.impact_creditable? end |
#significant_event? ⇒ Boolean
63 64 65 |
# File 'lib/docfolio/paragraph.rb', line 63 def significant_event? @tag_extractor.significant_event? end |
#tag?(tag) ⇒ Boolean
59 60 61 |
# File 'lib/docfolio/paragraph.rb', line 59 def tag?(tag) @tag_extractor.tag?(tag) end |