Class: Ikku::Reviewer

Inherits:
Object
  • Object
show all
Defined in:
lib/ikku/reviewer.rb

Instance Method Summary collapse

Constructor Details

#initialize(rule: nil) ⇒ Reviewer

Returns a new instance of Reviewer.



6
7
8
# File 'lib/ikku/reviewer.rb', line 6

def initialize(rule: nil)
  @rule = rule
end

Instance Method Details

#find(text) ⇒ Ikku::Song

Find one valid song from given text.

Returns:



12
13
14
15
16
17
18
19
# File 'lib/ikku/reviewer.rb', line 12

def find(text)
  nodes = parser.parse(text)
  nodes.length.times.find do |index|
    if (song = Song.new(nodes[index..-1], rule: @rule)).valid?
      break song
    end
  end
end

#judge(text) ⇒ true, false

Judge if given text is valid song or not.

Returns:

  • (true, false)


23
24
25
# File 'lib/ikku/reviewer.rb', line 23

def judge(text)
  Song.new(parser.parse(text), exactly: true, rule: @rule).valid?
end

#search(text) ⇒ Array<Array>

Search all valid songs from given text.

Returns:

  • (Array<Array>)


29
30
31
32
33
34
# File 'lib/ikku/reviewer.rb', line 29

def search(text)
  nodes = parser.parse(text)
  nodes.length.times.map do |index|
    Song.new(nodes[index..-1], rule: @rule)
  end.select(&:valid?)
end