Monday 26 June 2017

Generate random meaningful word, sentence or paragraph in Rails.

Sometimes we need generate randome meaningful sentences or paragraph for our app. We can acheive it in rails app with literate_randomizer gem.

So, in Gemfile-


gem 'literate_randomizer'


Run bundle

Now, this will provide LiterateRandomizer global Randommizer instance as LiterateRandomizer.global

We can use it simply like this -

    a) Generate word

		> LiterateRandomizer.word
		
		=> "Early"


		
		 > LiterateRandomizer.sentence

		 => "Surely we have believed."


    c) Generate paragraph

		> LiterateRandomizer.paragraph

		 => "Two hours later. ILLINGWORTH laughing and I. Meantime we should open the glare of the moon which. Faced by their own 			downfall. Anything more than actual specimen in this account of the dark indicate vegetable. While we should. Such is like two 			half-breeds from my return to mitigate. A fellow-countryman in his chair. Written upon the precipice we might there was no."


You can do customization in LiterateRandomizer global Randommizer instance.

As example -


	 > LiterateRandomizer.paragraph(:sentences => 2, :words => 5)

	 => "Visitin my house ready for. To-night however which took a!"

1 comment:

  1. Great Article. its is very very helpful for all of us and I never get bored while reading your article because, they are
    becomes a more and more interesting from the starting lines until the end.Ruby on Rails Online Course Hyderabad

    ReplyDelete