Class: Cosensee::ParsedLine
- Inherits:
-
Object
- Object
- Cosensee::ParsedLine
- Defined in:
- lib/cosensee/parsed_line.rb
Overview
parse a line
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#indent ⇒ Object
Returns the value of attribute indent.
-
#line_content ⇒ Object
Returns the value of attribute line_content.
-
#parsed ⇒ Object
Returns the value of attribute parsed.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#rest ⇒ Object
Returns the value of attribute rest.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #append_text(text:, raw_line:) ⇒ Object
- #codeblock? ⇒ Boolean
- #first_image ⇒ Object
- #indent_level ⇒ Object
-
#initialize(indent: nil, line_content: nil, content: [], rest: nil, raw: '', parsed: false) ⇒ ParsedLine
constructor
A new instance of ParsedLine.
- #internal_links ⇒ Object
- #line_content? ⇒ Boolean
- #match(pattern) ⇒ Object
- #parsed? ⇒ Boolean
- #rest? ⇒ Boolean
- #song_tagged? ⇒ Boolean
- #split_rest_by(str) ⇒ Object
- #to_s ⇒ Object
- #update(**attributes) ⇒ Object
Constructor Details
#initialize(indent: nil, line_content: nil, content: [], rest: nil, raw: '', parsed: false) ⇒ ParsedLine
Returns a new instance of ParsedLine.
6 7 8 9 10 11 12 13 |
# File 'lib/cosensee/parsed_line.rb', line 6 def initialize(indent: nil, line_content: nil, content: [], rest: nil, raw: '', parsed: false) @indent = indent @line_content = line_content @content = content @rest = rest @raw = raw @parsed = parsed end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
15 16 17 |
# File 'lib/cosensee/parsed_line.rb', line 15 def content @content end |
#indent ⇒ Object
Returns the value of attribute indent.
15 16 17 |
# File 'lib/cosensee/parsed_line.rb', line 15 def indent @indent end |
#line_content ⇒ Object
Returns the value of attribute line_content.
15 16 17 |
# File 'lib/cosensee/parsed_line.rb', line 15 def line_content @line_content end |
#parsed ⇒ Object
Returns the value of attribute parsed.
15 16 17 |
# File 'lib/cosensee/parsed_line.rb', line 15 def parsed @parsed end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
16 17 18 |
# File 'lib/cosensee/parsed_line.rb', line 16 def raw @raw end |
#rest ⇒ Object
Returns the value of attribute rest.
15 16 17 |
# File 'lib/cosensee/parsed_line.rb', line 15 def rest @rest end |
Instance Method Details
#==(other) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/cosensee/parsed_line.rb', line 85 def ==(other) other.is_a?(Cosensee::ParsedLine) && other.indent == indent && other.line_content == line_content && other.content == content && other.rest == rest && other.parsed? == parsed? end |
#append_text(text:, raw_line:) ⇒ Object
46 47 48 |
# File 'lib/cosensee/parsed_line.rb', line 46 def append_text(text:, raw_line:) self.line_content = line_content.append_text(text:, raw_line:) end |
#codeblock? ⇒ Boolean
18 19 20 |
# File 'lib/cosensee/parsed_line.rb', line 18 def codeblock? line_content.is_a?(Cosensee::Node::Codeblock) end |
#first_image ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/cosensee/parsed_line.rb', line 34 def first_image if line_content? line_content.is_a?(Node::Quote) && line_content.content.find { |elem| elem.is_a?(Node::ImageBracket) || elem.is_a?(Node::GyazoImageBracket) } else content.find { |elem| elem.is_a?(Node::ImageBracket) || elem.is_a?(Node::GyazoImageBracket) } end end |
#indent_level ⇒ Object
50 51 52 |
# File 'lib/cosensee/parsed_line.rb', line 50 def indent_level indent.level end |
#internal_links ⇒ Object
73 74 75 |
# File 'lib/cosensee/parsed_line.rb', line 73 def internal_links content.select { |c| c.is_a?(Cosensee::Node::InternalLinkBracket) || c.is_a?(Cosensee::Node::HashTag) }.map(&:anchor) end |
#line_content? ⇒ Boolean
42 43 44 |
# File 'lib/cosensee/parsed_line.rb', line 42 def line_content? !!line_content end |
#match(pattern) ⇒ Object
54 55 56 |
# File 'lib/cosensee/parsed_line.rb', line 54 def match(pattern) rest.match(pattern) end |
#parsed? ⇒ Boolean
22 23 24 |
# File 'lib/cosensee/parsed_line.rb', line 22 def parsed? @parsed end |
#rest? ⇒ Boolean
26 27 28 |
# File 'lib/cosensee/parsed_line.rb', line 26 def rest? !!rest end |
#song_tagged? ⇒ Boolean
30 31 32 |
# File 'lib/cosensee/parsed_line.rb', line 30 def song_tagged? content.any? { |elem| elem.is_a?(Node::HashTag) && elem.anchor == '楽曲' } end |
#split_rest_by(str) ⇒ Object
58 59 60 |
# File 'lib/cosensee/parsed_line.rb', line 58 def split_rest_by(str) rest.split(str, -1) end |
#to_s ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/cosensee/parsed_line.rb', line 77 def to_s if line_content? line_content.to_s else content.map(&:to_s).join end end |
#update(**attributes) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cosensee/parsed_line.rb', line 62 def update(**attributes) attributes.each do |key, value| # Check if the key is a valid accessor raise ArgumentError, "Attribute #{key} is not allowed to be updated." unless self.class.method_defined?("#{key}=") public_send("#{key}=", value) end self end |