Module: Pebbles::Dajare

Included in:
String
Defined in:
lib/pebbles/dajare.rb,
lib/pebbles/dajare/version.rb

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_dajare(phrase, degree: 2, region: 'jp') ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pebbles/dajare.rb', line 7

def generate_dajare(phrase, degree: 2, region: 'jp')
  components = phrase.scan(/./)

  prefix = components[0..-(degree+1)].join
  src_dajare = components[-degree..-1].join

  results = GoogleSuggest.suggest_for(src_dajare, region: region)

  dajares = results.map do |result|
    prefix + result.split(' ').shift
  end
  return dajares
end

Instance Method Details

#dajarize(degree: 2, region: 'jp') ⇒ Object


21
22
23
# File 'lib/pebbles/dajare.rb', line 21

def dajarize(degree: 2, region: 'jp')
  Pebbles::Dajare.generate_dajare(self.to_s, degree: degree, region: region)
end