Class: Syobocal::Comment::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/syobocal/comment/person.rb

Constant Summary collapse

PERSON_SEPARATOR =
""
ENCODED_SEPARATOR =
"\t"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, note) ⇒ Person

Returns a new instance of Person.



9
10
11
# File 'lib/syobocal/comment/person.rb', line 9

def initialize(name, note)
  @name, @note = name, note
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/syobocal/comment/person.rb', line 7

def name
  @name
end

#noteObject (readonly)

Returns the value of attribute note.



7
8
9
# File 'lib/syobocal/comment/person.rb', line 7

def note
  @note
end

Class Method Details

.multi_parse(str) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/syobocal/comment/person.rb', line 27

def self.multi_parse(str)
  Helper::Fragment.parse(str).to_a.map { |f|
    name = f.text
    note = f&.child&.to_s

    Person.new(name, note)
  }
end

.parse(str) ⇒ Object



21
22
23
24
25
# File 'lib/syobocal/comment/person.rb', line 21

def self.parse(str)
  _, name, note = *(str.match(/\A([^\(\)]+?)(?:\((.*?)\))?\Z/).to_a)

  Person.new(name&.strip, note&.strip)
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
# File 'lib/syobocal/comment/person.rb', line 13

def ==(other)
  other.instance_of?(self.class) && other.name == name && other.note == note
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/syobocal/comment/person.rb', line 17

def valid?
  !name.nil? && !name.empty?
end