Class: VivlioStarter::CLI::IndexCommands::MainReferenceSuggester::Chapter

Inherits:
Data
  • Object
show all
Defined in:
lib/vivlio_starter/cli/index/main_reference_suggester.rb

Overview

1 章ぶんの素材

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#basenameObject (readonly)

Returns the value of attribute basename

Returns:

  • (Object)

    the current value of basename



56
57
58
# File 'lib/vivlio_starter/cli/index/main_reference_suggester.rb', line 56

def basename
  @basename
end

#bodyObject (readonly)

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



56
57
58
# File 'lib/vivlio_starter/cli/index/main_reference_suggester.rb', line 56

def body
  @body
end

#headingsObject (readonly)

Returns the value of attribute headings

Returns:

  • (Object)

    the current value of headings



56
57
58
# File 'lib/vivlio_starter/cli/index/main_reference_suggester.rb', line 56

def headings
  @headings
end

Instance Method Details

#numberObject



64
# File 'lib/vivlio_starter/cli/index/main_reference_suggester.rb', line 64

def number = basename[/\A\d+/].to_i

#score(pattern) ⇒ Object



57
58
59
60
61
62
# File 'lib/vivlio_starter/cli/index/main_reference_suggester.rb', line 57

def score(pattern)
  weighted = HEADING_WEIGHTS.sum do |level, weight|
    headings.fetch(level, []).count { it.match?(pattern) } * weight
  end
  weighted + body.scan(pattern).size
end