Class: Aozora2Html::Tag::ReferenceMentioned

Inherits:
Inline show all
Defined in:
lib/aozora2html/tag/reference_mentioned.rb

Overview

参照先用

前方参照でこいつだけは中身をチェックする子要素を持つAozora2Html::Tag::Inlineは全てこいつのサブクラス

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Aozora2Html::Tag

#char_type, #inspect, #syntax_error

Constructor Details

#initialize(*_args) ⇒ ReferenceMentioned

rubocop:disable Lint/MissingSuper



12
13
14
15
16
# File 'lib/aozora2html/tag/reference_mentioned.rb', line 12

def initialize(*_args) # rubocop:disable Lint/MissingSuper
  return unless defined?(@target) && block_element?(@target)

  syntax_error
end

Instance Attribute Details

#targetObject

Returns the value of attribute target.



10
11
12
# File 'lib/aozora2html/tag/reference_mentioned.rb', line 10

def target
  @target
end

Instance Method Details

#block_element?(elt) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
# File 'lib/aozora2html/tag/reference_mentioned.rb', line 18

def block_element?(elt)
  case elt
  when Array
    elt.any? { |x| block_element?(x) }
  when String
    elt.include?('<div')
  else
    elt.is_a?(Aozora2Html::Tag::Block)
  end
end

#target_stringObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/aozora2html/tag/reference_mentioned.rb', line 29

def target_string
  case @target
  when Aozora2Html::Tag::ReferenceMentioned
    @target.target_string
  when Array
    @target.collect do |x|
      if x.is_a?(Aozora2Html::Tag::ReferenceMentioned)
        x.target_string
      else
        x
      end
    end.join
  else
    @target
  end
end