Class: Haikuable::Checker

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

Constant Summary collapse

HAIKU_SYLLABLE_COUNT =
17

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Checker

Returns a new instance of Checker.

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/haikuable.rb', line 9

def initialize(string)
  @string      = string
  @line_counts = { line1: 0, line2: 0, line3: 0 }
  raise ArgumentError.new('must be called on a string') unless string.is_a?(String)
end

Instance Attribute Details

#line_countsObject

Returns the value of attribute line_counts.



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

def line_counts
  @line_counts
end

#stringObject

Returns the value of attribute string.



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

def string
  @string
end

Instance Method Details

#is_haiku?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/haikuable.rb', line 15

def is_haiku?
  return false unless string_syllable_count == haiku_syllable_count
  individual_syllables.each do |syl_count|
    line_counts.each do |key, count|
      if line_counts[key] < haiku_lines[key]
        line_counts[key] += syl_count
      end
    end
  end
  line_counts == haiku_lines
end