Class: LoremIpsumForgery
- Defined in:
- lib/forgeries/lorem_ipsum_forgery.rb
Class Method Summary collapse
- .character(options = {}) ⇒ Object
- .characters(quantity = 10, options = {}) ⇒ Object
- .paragraph(options = {}) ⇒ Object
- .paragraphs(quantity = 2, options = {}) ⇒ Object
- .sentence(options = {}) ⇒ Object
- .sentences(quantity = 2, options = {}) ⇒ Object
- .text(what = :sentence, quantity = 2, options = {}) ⇒ Object
- .word(options = {}) ⇒ Object
- .words(quantity = 10, options = {}) ⇒ Object
Methods inherited from Forgery
Class Method Details
.character(options = {}) ⇒ Object
25 26 27 |
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 25 def self.character(={}) self.characters(1, ) end |
.characters(quantity = 10, options = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 29 def self.characters(quantity=10, ={}) .merge!(:random_limit => lorem_ipsum_characters.length-quantity) if quantity.is_a?(Fixnum) lorem_ipsum_characters[range_from_quantity(quantity, )] end |
.paragraph(options = {}) ⇒ Object
55 56 57 |
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 55 def self.paragraph(={}) self.paragraphs(1, ) end |
.paragraphs(quantity = 2, options = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 59 def self.paragraphs(quantity=2, ={}) .reverse_merge!(:separator => "\n\n", :wrap => { :start => "", :end => "" }, :html => false, :sentences => 3) .merge!(:random_limit => (dictionaries[:lorem_ipsum].length/[:sentences])-quantity) if quantity.is_a?(Fixnum) if [:html] [:wrap] = { :start => "<p>", :end => "</p>" } end range = range_from_quantity(quantity, ) start = range.first * [:sentences] paragraphs = [] range.to_a.length.times do |i| paragraphs << ( [:wrap][:start] + dictionaries[:lorem_ipsum][start..(start+[:sentences]-1)].join(" ") + [:wrap][:end] ) start += [:sentences] end paragraphs.join([:separator]) end |
.sentence(options = {}) ⇒ Object
45 46 47 |
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 45 def self.sentence(={}) self.sentences(1, ) end |
.sentences(quantity = 2, options = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 49 def self.sentences(quantity=2, ={}) .merge!(:random_limit => (dictionaries[:lorem_ipsum].length-quantity)) if quantity.is_a?(Fixnum) dictionaries[:lorem_ipsum][range_from_quantity(quantity, )].join(" ") end |
.text(what = :sentence, quantity = 2, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 3 def self.text(what=:sentence, quantity=2, ={}) case what when :character self.character() when :characters self.characters(quantity, ) when :word self.word() when :words self.words(quantity, ) when :sentence self.sentence() when :sentences self.sentences(quantity, ) when :paragraph self.paragraph() when :paragraphs self.paragraphs(quantity, ) end end |
.word(options = {}) ⇒ Object
35 36 37 |
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 35 def self.word(={}) self.words(1, ) end |
.words(quantity = 10, options = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 39 def self.words(quantity=10, ={}) .merge!(:random_limit => lorem_ipsum_words.length-quantity) if quantity.is_a?(Fixnum) lorem_ipsum_words[range_from_quantity(quantity, )].join(" ") end |