Class: Jekyll::RpLogs::LogLine
- Inherits:
-
Object
- Object
- Jekyll::RpLogs::LogLine
- Defined in:
- lib/jekyll/rp_logs/rp_logline.rb
Constant Summary collapse
- RP_FLAG =
"!RP".freeze
- OOC_FLAG =
"!OOC".freeze
- MERGE_FLAG =
"!MERGE".freeze
- SPLIT_FLAG =
"!SPLIT".freeze
Class Attribute Summary collapse
-
.max_seconds_between_posts ⇒ Object
readonly
Returns the value of attribute max_seconds_between_posts.
-
.ooc_start_delimiters ⇒ Object
readonly
Returns the value of attribute ooc_start_delimiters.
Instance Attribute Summary collapse
-
#base_type ⇒ Object
readonly
Some things depend on the original type of the line (nick format).
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#last_merged_timestamp ⇒ Object
readonly
Timestamp of the most recent line this line was merged with, to allow merging consecutive lines each MAX_SECONDS_BETWEEN_POSTS apart.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output_type ⇒ Object
readonly
Some things depend on the original type of the line (nick format).
-
#sender ⇒ Object
readonly
Returns the value of attribute sender.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(timestamp, options = {}, sender:, contents:, flags:, type:, mode: " ") ⇒ LogLine
constructor
A new instance of LogLine.
- #inspect ⇒ Object
- #merge!(next_line) ⇒ Object
- #merge_flag? ⇒ Boolean
-
#mergeable_with?(next_line) ⇒ Boolean
Check if this line can be merged with the given line.
- #output ⇒ Object
- #output_sender ⇒ Object
- #output_tags ⇒ Object
- #output_timestamp ⇒ Object
-
#rp? ⇒ Boolean
Returns true if this line has the output_type :rp.
- #split_flag? ⇒ Boolean
Constructor Details
#initialize(timestamp, options = {}, sender:, contents:, flags:, type:, mode: " ") ⇒ LogLine
Returns a new instance of LogLine.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 37 def initialize(, = {}, sender:, contents:, flags:, type:, mode: " ") @timestamp = # Initialize to be the same as @timestamp @last_merged_timestamp = @mode = mode @sender = sender @contents = contents @flags = flags.split(" ") @base_type = type @output_type = type @options = classify end |
Class Attribute Details
.max_seconds_between_posts ⇒ Object (readonly)
Returns the value of attribute max_seconds_between_posts.
27 28 29 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 27 def max_seconds_between_posts @max_seconds_between_posts end |
.ooc_start_delimiters ⇒ Object (readonly)
Returns the value of attribute ooc_start_delimiters.
27 28 29 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 27 def ooc_start_delimiters @ooc_start_delimiters end |
Instance Attribute Details
#base_type ⇒ Object (readonly)
Some things depend on the original type of the line (nick format)
13 14 15 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 13 def base_type @base_type end |
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
11 12 13 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 11 def contents @contents end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
11 12 13 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 11 def flags @flags end |
#last_merged_timestamp ⇒ Object (readonly)
Timestamp of the most recent line this line was merged with, to allow merging consecutive lines each MAX_SECONDS_BETWEEN_POSTS apart
18 19 20 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 18 def @last_merged_timestamp end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
11 12 13 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 11 def mode @mode end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 14 def @options end |
#output_type ⇒ Object (readonly)
Some things depend on the original type of the line (nick format)
13 14 15 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 13 def output_type @output_type end |
#sender ⇒ Object (readonly)
Returns the value of attribute sender.
11 12 13 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 11 def sender @sender end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
11 12 13 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 11 def @timestamp end |
Class Method Details
.extract_settings(config) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 29 def extract_settings(config) @max_seconds_between_posts = config.fetch("max_seconds_between_posts", @max_seconds_between_posts) @ooc_start_delimiters = config.fetch("ooc_start_delimiters", @ooc_start_delimiters).freeze end |
Instance Method Details
#inspect ⇒ Object
194 195 196 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 194 def inspect "<#{@mode}#{@sender}> (#{@base_type} -> #{@output_type}) #{@contents}" end |
#merge!(next_line) ⇒ Object
147 148 149 150 151 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 147 def merge!(next_line) @contents += "#{space_between_lines}#{next_line.contents}" @last_merged_timestamp = next_line. self end |
#merge_flag? ⇒ Boolean
178 179 180 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 178 def merge_flag? @flags.include? MERGE_FLAG end |
#mergeable_with?(next_line) ⇒ Boolean
Check if this line can be merged with the given line. In order to be merged, the two lines must fulfill the following requirements:
-
The timestamp difference is >= 0 and <= MAX_SECONDS_BETWEEN POSTS (close_enough_timestamps?)
-
The lines have the same sender (same_sender?)
-
The first line has output_type :rp (rp?)
-
The next line has output_type :rp OR the sender has been specified as someone who splits to normal text
Exceptions:
-
If the next line has the SPLIT flag, it will never be merged
-
If the next line has the MERGE flag, it will always be merged
130 131 132 133 134 135 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 130 def mergeable_with?(next_line) # Perform the checks for the override flags return true if next_line.merge_flag? return false if next_line.split_flag? mergeable_ignoring_flags?(next_line) end |
#output ⇒ Object
73 74 75 76 77 78 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 73 def output tag_open, tag_close = # Escape any HTML special characters in the input escaped_content = CGI.escapeHTML(@contents) "#{tag_open}#{}#{output_sender} #{escaped_content}#{tag_close}" end |
#output_sender ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 90 def output_sender case @base_type when :rp return "#{@sender}" when :ooc return "<#{@mode}#{@sender}>" else # Explode. fail "No known type: #{@base_type}" end end |
#output_tags ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 102 def tag_class = case @output_type when :rp then "rp" when :ooc then "ooc" else # Explode. fail "No known type: #{@output_type}" end tag_open = "<p class=\"#{tag_class}\">" tag_close = "</p>" [tag_open, tag_close] end |
#output_timestamp ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 80 def # String used for the timestamp anchors anchor = @timestamp.strftime("%Y-%m-%d_%H:%M:%S") # String used when hovering over timestamps (friendly long-form) title = @timestamp.strftime("%H:%M:%S %B %-d, %Y") # String actually displayed on page display = @timestamp.strftime("%H:%M") "<a name=\"#{anchor}\" title=\"#{title}\" href=\"##{anchor}\">#{display} </a>" end |
#rp? ⇒ Boolean
Returns true if this line has the output_type :rp
170 171 172 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 170 def rp? @output_type == :rp end |
#split_flag? ⇒ Boolean
174 175 176 |
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 174 def split_flag? @flags.include? SPLIT_FLAG end |