Class: Cosensee::ParsedBracket

Inherits:
Object
  • Object
show all
Defined in:
lib/cosensee/parsed_bracket.rb

Overview

parse a line

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content: []) ⇒ ParsedBracket

Returns a new instance of ParsedBracket.



6
7
8
9
# File 'lib/cosensee/parsed_bracket.rb', line 6

def initialize(content: [])
  @content = content
  @parsed = false
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



11
12
13
# File 'lib/cosensee/parsed_bracket.rb', line 11

def content
  @content
end

Instance Method Details

#==(other) ⇒ Object



36
37
38
39
40
# File 'lib/cosensee/parsed_bracket.rb', line 36

def ==(other)
  other.is_a?(Cosensee::ParsedBracket) &&
    other.content == content &&
    other.parsed? == parsed?
end

#first_contentObject



32
33
34
# File 'lib/cosensee/parsed_bracket.rb', line 32

def first_content
  content.first
end

#parsed?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/cosensee/parsed_bracket.rb', line 13

def parsed?
  @parsed
end

#single_text?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cosensee/parsed_bracket.rb', line 28

def single_text?
  content.size == 1 && content.first.is_a?(String)
end

#update(**attributes) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/cosensee/parsed_bracket.rb', line 17

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