Class: Syobocal::Comment::Element::Row

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr_node, value_node) ⇒ Row

Returns a new instance of Row.



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

def initialize(attr_node, value_node)
  @attr_node, @value_node = attr_node, value_node
end

Instance Attribute Details

#attr_nodeObject (readonly)

Returns the value of attribute attr_node.



5
6
7
# File 'lib/syobocal/comment/element/row.rb', line 5

def attr_node
  @attr_node
end

#value_nodeObject (readonly)

Returns the value of attribute value_node.



5
6
7
# File 'lib/syobocal/comment/element/row.rb', line 5

def value_node
  @value_node
end

Class Method Details

.match?(line) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/syobocal/comment/element/row.rb', line 15

def self.match?(line)
  line.start_with?(":")
end

.parse(line) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/syobocal/comment/element/row.rb', line 19

def self.parse(line)
  if line.scan(":").length == 1
    # NOTE :が1つしか含まれない行は:以降が値となる
    m = line.match(/\A:(.*)\Z/)
    attr = Element::Blank.new
    value = Element::TextNode.parse(m[1])
  else
    m = line.match(/\A:([^:]*?):(.*)\Z/)
    attr = Element::TextNode.parse(m[1])
    value = Element::TextNode.parse(m[2])
  end

  Element::Row.new(attr, value)
end

Instance Method Details

#==(other) ⇒ Object



11
12
13
# File 'lib/syobocal/comment/element/row.rb', line 11

def ==(other)
  other.instance_of?(self.class) && other.attr_node == attr_node && other.value_node == value_node
end