<file_sep># ShinyWookie
[![Build Status](https://travis-ci.org/kvannotten/shiny_wookie.png?branch=master)](https://travis-ci.org/kvannotten/shiny_wookie)

ShinyWookie is a command line utility that generates documents with random data for you. 

## Installation

Install via the command line:

    $ gem install shiny_wookie

## Usage

After installation you can run ShinyWookie as follows:

    $ shiny_wookie -a #_OF_DOCUMENTS_YOU_WANT_TO_GENERATE

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
<file_sep># coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'shiny_wookie/version'

Gem::Specification.new do |spec|
  spec.name                  = "shiny_wookie"
  spec.version               = ShinyWookie::VERSION
  spec.authors               = ["<NAME>"]
  spec.email                 = ["<EMAIL>"]
  spec.description           = %q{A gem that generates random documents}
  spec.summary               = %q{This gem creates a specified amount documents, containing randomly generated text}
  spec.homepage              = "https://github.com/kvannotten/shiny_wookie"
  spec.license               = "MIT"
                     
  spec.files                 = `git ls-files`.split($/)
  spec.executables           = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
  spec.test_files            = spec.files.grep(%r{^(test|spec|features)/})
  spec.require_paths         = ["lib"]
  spec.required_ruby_version = '>= 1.9'

  # development dependencies
  {"bundler" => "~> 1.3", "rake" => "> 0", "rspec" => "> 0", "simplecov" => "> 0"}.each do |gem_name, gem_version|
    spec.add_development_dependency gem_name, gem_version
  end
  
  # runtime dependencies
  ["gabbler"].each do |gem_name|
    spec.add_dependency gem_name
  end
end
<file_sep>require 'simplecov'
SimpleCov.start

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'shiny_wookie'
require 'gabbler'
<file_sep>require 'spec_helper'

describe ShinyWookie do
  it 'has a version number' do
    ShinyWookie::VERSION.should_not be_nil
  end
  
  context "documents" do
    it 'returns an array' do
      documents = ShinyWookie.generate_documents
    
      documents.should be_an_instance_of Array
    end

    it 'contains documents' do
      documents = ShinyWookie.generate_documents
    
      documents.first.should be_an_instance_of ShinyWookie::Document
    end
  
  end
  
  it "has a gabbler" do 
    gabbler = ShinyWookie.gabbler
    
    gabbler.should be_an_instance_of Gabbler
  end
  
  it "has one gabbler" do
    gabbler = ShinyWookie.gabbler
    gabbler2 = ShinyWookie.gabbler
    
    gabbler.object_id.should eql gabbler2.object_id
  end

end
<file_sep>require 'gabbler'

module ShinyWookie
  class Document
    attr_accessor :content
    
    def initialize 
      @content = generate_content
    end
    
    def write_to_file *args
      options = args.last.is_a?(Hash) ? args.last : {}
      
      prefix = (options.member?(:prefix) ? options[:prefix] : "")
      name = (options.member?(:name) ? options[:name] : nil)
      suffix = (options.member?(:suffix) ? options[:suffix] : "")
      extension = (options.member?(:extension) ? options[:extension] : "txt")
      
      raise ArgumentError if name.nil? 
      
      File.open("#{prefix}#{name}#{suffix}.#{extension}", "w") { |f| f.write @content }
    end
    
    private
    
    def generate_content
      sentences = rand(10..100)
      @content = ShinyWookie.gabbler.sentence
      sentences.times { @content << ShinyWookie.gabbler.sentence << " " }
      
      @content
    end
    
  end
end<file_sep>require 'spec_helper'
require 'shiny_wookie/document'

describe ShinyWookie::Document do
  before :each do
    @document = ShinyWookie::Document.new
  end
  
  subject { @document }
  
  context :content do
    it { should respond_to :content }
    
    its(:content) { should_not be_empty }
    
    it "is unique" do 
      doc2 = ShinyWookie::Document.new
      
      @document.content.should_not eql doc2.content
    end
  end
  
  context "write file" do
    it "writes content" do
      @document.write_to_file :prefix => "cv_", :name => "document", :extension => "txt"
  
      IO.read("cv_document.txt").should eql @document.content
      File.delete("cv_document.txt")
    end
  
    it "has a file name" do
      expect { @document.write_to_file :prefix => "doc_" }.to raise_error ArgumentError
    end
  end
  
end<file_sep>#!/usr/bin/env ruby

require 'optparse'
require 'shiny_wookie'

$stdout.sync = true

amount = 1
file = ''

options = OptionParser.new do |o|
  o.banner = 
    "Usage: shiny_wookie [options] \n\n"
  
  o.on("-a", "--amount X", "generate X documents") do |k|
    amount = k.to_i
  end
  
  o.on("-f", "--file FILE" , "learn this document to parse strings from") do |k|
    file = k unless k.nil? or k.eql? ""
  end 

  o.on('-h', "--help", "show this help") { puts o; exit }
end

begin
  args = options.parse!
  
  documents = ShinyWookie::generate_documents amount
  
  documents.each_with_index do |document, index|
    document.write_to_file :prefix => "cv_", :name => Time.now.strftime("%Y_%m_%d_%s"), :suffix => "_#{index}"
  end
rescue OptionParser::MissingArgument
  puts "I don't understand what you mean :-("
  puts
  puts options
end

<file_sep>require "shiny_wookie/version"
require "shiny_wookie/document"

module ShinyWookie
  
  def self.generate_documents amount = 1
    documents = []
    
    return [] if amount.to_i < 1
    
    1.upto amount.to_i do
      documents << Document.new
    end
    
    documents
  end
  
  def self.gabbler
    if @gabbler.nil?
      @gabbler = Gabbler.new
      story_file = File.join(File.dirname(File.expand_path(__FILE__)), '../resources/huckleberry.txt')
      story = File.read(story_file)
      gabbler.learn story
    end
    
    @gabbler
  end
  
end
