Class: Jekyll::RpLogs::LogLine

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(timestamp, options = {}, sender:, contents:, flags:, type:, mode: " ")
  @timestamp = timestamp
  # Initialize to be the same as @timestamp
  @last_merged_timestamp = timestamp
  @mode = mode
  @sender = sender
  @contents = contents
  @flags = flags.split(" ")

  @base_type = type
  @output_type = type

  @options = options

  classify
end

Class Attribute Details

.max_seconds_between_postsObject (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_delimitersObject (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_typeObject (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

#contentsObject (readonly)

Returns the value of attribute contents.



11
12
13
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 11

def contents
  @contents
end

#flagsObject (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_timestampObject (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
  @last_merged_timestamp
end

#modeObject (readonly)

Returns the value of attribute mode.



11
12
13
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 11

def mode
  @mode
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 14

def options
  @options
end

#output_typeObject (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

#senderObject (readonly)

Returns the value of attribute sender.



11
12
13
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 11

def sender
  @sender
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



11
12
13
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 11

def timestamp
  @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

#inspectObject



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.timestamp
  self
end

#merge_flag?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

#outputObject



73
74
75
76
77
78
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 73

def output
  tag_open, tag_close = output_tags
  # Escape any HTML special characters in the input
  escaped_content = CGI.escapeHTML(@contents)
  "#{tag_open}#{output_timestamp}#{output_sender} #{escaped_content}#{tag_close}"
end

#output_senderObject



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 "&lt;#{@mode}#{@sender}&gt;"
  else
    # Explode.
    fail "No known type: #{@base_type}"
  end
end

#output_tagsObject



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 102

def output_tags
  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_timestampObject



80
81
82
83
84
85
86
87
88
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 80

def output_timestamp
  # 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

Returns:

  • (Boolean)


170
171
172
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 170

def rp?
  @output_type == :rp
end

#split_flag?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/jekyll/rp_logs/rp_logline.rb', line 174

def split_flag?
  @flags.include? SPLIT_FLAG
end