Class: Kimoby
- Inherits:
-
Object
- Object
- Kimoby
- Defined in:
- lib/kimoby.rb
Instance Attribute Summary collapse
-
#dict ⇒ Object
readonly
Returns the value of attribute dict.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#res ⇒ Object
readonly
Returns the value of attribute res.
Instance Method Summary collapse
- #generate(words) ⇒ Object
-
#initialize(path, word_length = 6) ⇒ Kimoby
constructor
A new instance of Kimoby.
- #paginate(page = 1, per_page = 100) ⇒ Object
Constructor Details
#initialize(path, word_length = 6) ⇒ Kimoby
Returns a new instance of Kimoby.
10 11 12 13 14 |
# File 'lib/kimoby.rb', line 10 def initialize(path, word_length = 6) @dict = Utils.read_from_file(path) @length = word_length @res = [] end |
Instance Attribute Details
#dict ⇒ Object (readonly)
Returns the value of attribute dict.
8 9 10 |
# File 'lib/kimoby.rb', line 8 def dict @dict end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
8 9 10 |
# File 'lib/kimoby.rb', line 8 def length @length end |
#res ⇒ Object (readonly)
Returns the value of attribute res.
8 9 10 |
# File 'lib/kimoby.rb', line 8 def res @res end |
Instance Method Details
#generate(words) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/kimoby.rb', line 16 def generate(words) if words.is_a?(Array) && words.size > 0 words.permutation(2).uniq.each do |word| @res << word[0].strip + word[1].strip if word[0].strip.length + word[1].strip.length == @length end end end |
#paginate(page = 1, per_page = 100) ⇒ Object
24 25 26 27 |
# File 'lib/kimoby.rb', line 24 def paginate(page = 1, per_page = 100) res = @res.paginate(page: page, per_page: per_page) puts "Result | #{ per_page } first word on the first page: #{res}" end |