class LoremKnight::Panther

Attributes

has_pre_sentence[RW]
list_size[RW]
paragraph_size[RW]
sentence_size[RW]
word_length[RW]

Public Class Methods

new() click to toggle source
# File lib/lorem-knight/panther.rb, line 11
def initialize
  #
  source = File.open("#{$source_location}/raw/words.txt", "r+")
  @content = source.sysread(source.size).split(" ")
  
  # initialize default lorem config vars
  @paragraph_size = 70
  @sentence_size = 7
  @list_size = 5
  @word_length = 20
  @list_standart_size = 10
  
  @content_type = "RAW"
  @has_pre_sentence = false
end

Public Instance Methods

generate_list() click to toggle source
# File lib/lorem-knight/panther.rb, line 82
def generate_list
  pre_sentence = @has_pre_sentence == true ? "რომელმან შექმნა სამყარო" : ""
    list = "<ul><li>"
    randomSize = rand(20) 

    @list_standart_size.times do |x|
            list += " #{pre_sentence}"
            randomSize.times do |y|
                    list += y != randomSize-1 ? " #{@content[rand(@content.size-1)]}" : " #{@content[rand(@content.size-1)]}</li>"
            end
            list += x != @list_standart_size-1 ? "<li>" : "</ul>"
     end
    return list.force_encoding('UTF-8')
end
generate_lorem(quantity, length, prefix = '') click to toggle source
# File lib/lorem-knight/panther.rb, line 64
def generate_lorem(quantity, length, prefix = '')
  pre_sentence = @has_pre_sentence == true ? "რომელმან შექმნა სამყარო" : ""
  lorem = @content_type == 'text/html' ? "<p> #{pre_sentence} " : "#{pre_sentence} "

  quantity.times do |i|
    length.times do
      lorem += (@content[rand(@content.size)] + " ").force_encoding('UTF-8')
    end
      case(@content_type)
      when "text/html"
        lorem += i != quantity - 1 ? " </p>  <p> #{pre_sentence} " : " </p>"
      when "RAW"
        lorem += i != quantity - 1 ? "\n #{pre_sentence} " : ""
      end
  end
  return lorem.force_encoding('UTF-8')
end
get_list(quantity) click to toggle source
# File lib/lorem-knight/panther.rb, line 35
def get_list(quantity)
  lists = ""
  quantity.to_i.times { lists += generate_list }
  return lists
end
get_paragraph(quantity) click to toggle source
# File lib/lorem-knight/panther.rb, line 31
def get_paragraph(quantity)
  generate_lorem(quantity, @paragraph_size)
end
get_sentence(quantity) click to toggle source
# File lib/lorem-knight/panther.rb, line 27
def get_sentence(quantity)
  generate_lorem(quantity, @sentence_size)
end
get_words(quantity) click to toggle source
# File lib/lorem-knight/panther.rb, line 41
def get_words(quantity)
  words = ""
  word_array = words.split(" ")

  while word_array.length < quantity.to_i do
    pending_word = @content[rand(@content.size)]
    words += pending_word.length <= @word_length ? pending_word + " " : ""
    word_array = words.split(" ")
  end
  return words.force_encoding('UTF-8')
end
set_content_type(type) click to toggle source
# File lib/lorem-knight/panther.rb, line 53
def set_content_type(type)
  case(type.to_s)
  when "html"
    @content_type = "text/html"
  when "raw"
    @content_type = "RAW"
  else
    @content_type = "RAW"
  end
end