Module: Decidim::Faker::Localized
- Defined in:
- lib/decidim/faker/localized.rb
Overview
A Custom Faker wrapper so we can easily generate fake data for each locale in localized attributes.
Class Method Summary collapse
-
.character ⇒ Object
Builds a Lorem Ipsum character.
-
.characters(*args) ⇒ Object
Builds many Lorem Ipsum characters.
-
.company ⇒ Object
Fakes a company name.
-
.literal(text) ⇒ Object
Sets the given text as the value for each locale.
-
.name ⇒ Object
Fakes a person name.
-
.paragraph(*args) ⇒ Object
Builds a paragraph with Lorem Ipsum words.
-
.paragraphs(*args) ⇒ Object
Builds many paragraphs with Lorem Ipsum words.
-
.question(*args) ⇒ Object
Builds a question with Lorem Ipsum words.
-
.questions(*args) ⇒ Object
Builds many questions with Lorem Ipsum words.
-
.sentence(*args) ⇒ Object
Builds a sentence with Lorem Ipsum words.
-
.sentences(*args) ⇒ Object
Builds many sentences with Lorem Ipsum words.
-
.word ⇒ Object
Builds a Lorem Ipsum word.
-
.words(*args) ⇒ Object
Builds many Lorem Ipsum words.
-
.wrapped(before, after) ⇒ Object
Wrapps a text build by the block with some other text.o.
Class Method Details
.character ⇒ Object
Builds a Lorem Ipsum character.
Returns a Hash with a value for each locale.
48 49 50 51 52 |
# File 'lib/decidim/faker/localized.rb', line 48 def self.character localized do ::Faker::Lorem.character end end |
.characters(*args) ⇒ Object
Builds many Lorem Ipsum characters. See Faker::Lorem for options.
Returns a Hash with a value for each locale.
57 58 59 60 61 |
# File 'lib/decidim/faker/localized.rb', line 57 def self.characters(*args) localized do ::Faker::Lorem.characters(*args) end end |
.company ⇒ Object
Fakes a company name.
Returns a Hash with a value for each locale.
12 13 14 15 16 |
# File 'lib/decidim/faker/localized.rb', line 12 def self.company localized do ::Faker::Company.name end end |
.literal(text) ⇒ Object
Sets the given text as the value for each locale.
text - The String text to set for each locale.
Returns a Hash with a value for each locale.
122 123 124 125 126 |
# File 'lib/decidim/faker/localized.rb', line 122 def self.literal(text) I18n.available_locales.inject({}) do |result, locale| result.update(locale => text) end end |
.name ⇒ Object
Fakes a person name.
Returns a Hash with a value for each locale.
21 22 23 24 25 |
# File 'lib/decidim/faker/localized.rb', line 21 def self.name localized do ::Faker::Name.name end end |
.paragraph(*args) ⇒ Object
Builds a paragraph with Lorem Ipsum words. See Faker::Lorem for options.
Returns a Hash with a value for each locale.
84 85 86 87 88 |
# File 'lib/decidim/faker/localized.rb', line 84 def self.paragraph(*args) localized do ::Faker::Lorem.paragraph(*args) end end |
.paragraphs(*args) ⇒ Object
Builds many paragraphs with Lorem Ipsum words. See Faker::Lorem for options.
Returns a Hash with a value for each locale.
93 94 95 96 97 |
# File 'lib/decidim/faker/localized.rb', line 93 def self.paragraphs(*args) localized do ::Faker::Lorem.paragraphs(*args) end end |
.question(*args) ⇒ Object
Builds a question with Lorem Ipsum words. See Faker::Lorem for options.
Returns a Hash with a value for each locale.
102 103 104 105 106 |
# File 'lib/decidim/faker/localized.rb', line 102 def self.question(*args) localized do ::Faker::Lorem.question(*args) end end |
.questions(*args) ⇒ Object
Builds many questions with Lorem Ipsum words. See Faker::Lorem for options.
Returns a Hash with a value for each locale.
111 112 113 114 115 |
# File 'lib/decidim/faker/localized.rb', line 111 def self.questions(*args) localized do ::Faker::Lorem.questions(*args) end end |
.sentence(*args) ⇒ Object
Builds a sentence with Lorem Ipsum words. See Faker::Lorem for options.
Returns a Hash with a value for each locale.
66 67 68 69 70 |
# File 'lib/decidim/faker/localized.rb', line 66 def self.sentence(*args) localized do ::Faker::Lorem.sentence(*args) end end |
.sentences(*args) ⇒ Object
Builds many sentences with Lorem Ipsum words. See Faker::Lorem for options.
Returns a Hash with a value for each locale.
75 76 77 78 79 |
# File 'lib/decidim/faker/localized.rb', line 75 def self.sentences(*args) localized do ::Faker::Lorem.sentences(*args) end end |
.word ⇒ Object
Builds a Lorem Ipsum word.
Returns a Hash with a value for each locale.
30 31 32 33 34 |
# File 'lib/decidim/faker/localized.rb', line 30 def self.word localized do ::Faker::Lorem.word end end |
.words(*args) ⇒ Object
Builds many Lorem Ipsum words. See Faker::Lorem for options.
Returns a Hash with a value for each locale.
39 40 41 42 43 |
# File 'lib/decidim/faker/localized.rb', line 39 def self.words(*args) localized do ::Faker::Lorem.words(*args) end end |
.wrapped(before, after) ⇒ Object
Wrapps a text build by the block with some other text.o
before - The String text to inject at the begining of each value. after - The String text to inject at the end of each value. block - A Block that generates a Hash with a text for each locale.
Example:
Decidim::Faker::Localized.wrapped("<p>", "</p>") do
Decidim::Faker::Localized.sentence(5)
end
Returns a Hash with a value for each locale.
141 142 143 144 145 146 |
# File 'lib/decidim/faker/localized.rb', line 141 def self.wrapped(before, after) result = yield result.inject({}) do |wrapped, (locale, text)| wrapped.update(locale => [before, text, after].join) end end |