Class: Faker::Hipster

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/hipster.rb

Constant Summary

Constants inherited from Base

Base::Letters, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3) ⇒ Object



37
38
39
# File 'lib/faker/default/hipster.rb', line 37

def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3)
  sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental).join(' ')
end

.paragraph_by_chars(chars = 256, supplemental = false) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/faker/default/hipster.rb', line 49

def paragraph_by_chars(chars = 256, supplemental = false)
  paragraph = paragraph(3, supplemental)

  paragraph += ' ' + paragraph(3, supplemental) while paragraph.length < chars

  paragraph[0...chars - 1] + '.'
end

.paragraphs(paragraph_count = 3, supplemental = false) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/faker/default/hipster.rb', line 41

def paragraphs(paragraph_count = 3, supplemental = false)
  [].tap do |paragraphs|
    1.upto(resolve(paragraph_count)) do
      paragraphs << paragraph(3, supplemental)
    end
  end
end

.sentence(word_count = 4, supplemental = false, random_words_to_add = 6) ⇒ Object



25
26
27
# File 'lib/faker/default/hipster.rb', line 25

def sentence(word_count = 4, supplemental = false, random_words_to_add = 6)
  words(word_count + rand(random_words_to_add.to_i).to_i, supplemental, true).join(' ').capitalize + '.'
end

.sentences(sentence_count = 3, supplemental = false) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/faker/default/hipster.rb', line 29

def sentences(sentence_count = 3, supplemental = false)
  [].tap do |sentences|
    1.upto(resolve(sentence_count)) do
      sentences << sentence(3, supplemental)
    end
  end
end

.wordObject



6
7
8
9
# File 'lib/faker/default/hipster.rb', line 6

def word
  random_word = sample(translate('faker.hipster.words'))
  random_word =~ /\s/ ? word : random_word
end

.words(num = 3, supplemental = false, spaces_allowed = false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/faker/default/hipster.rb', line 11

def words(num = 3, supplemental = false, spaces_allowed = false)
  resolved_num = resolve(num)
  word_list = (
    translate('faker.hipster.words') +
    (supplemental ? translate('faker.lorem.words') : [])
  )
  word_list *= ((resolved_num / word_list.length) + 1)

  return shuffle(word_list)[0, resolved_num] if spaces_allowed

  words = shuffle(word_list)[0, resolved_num]
  words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
end