robohash 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .redcar/
6
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in robohash.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ #Description
2
+ This gem downloads the user defined number of robohash images from the robohash.org
3
+
4
+ #Installation
5
+ `gem install robohash`
6
+
7
+ OR in your gemfile
8
+
9
+ `gem robohash`
10
+
11
+ #Use
12
+ 1. Download Images
13
+ `Robohash.get_images`
14
+
15
+ 2.Change default number of images to be downloaded
16
+ ` Robohash.default_num=150`
17
+
18
+ 3.Change default directory to download images
19
+ ` Robohash.default_directory="images/robots"`
20
+
@@ -0,0 +1,3 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,57 @@
1
+ require "robohash/version"
2
+ require 'httparty'
3
+ require 'fileutils'
4
+ module Robohash
5
+ @default_num = 3
6
+ @default_directory = "robo_hash_images"
7
+
8
+ module_function
9
+ def default_num; @default_num end
10
+ def default_num= v; @default_num = v end
11
+ def default_directory; @default_directory end
12
+ def default_directory= v; @default_directory = v end
13
+ def Version; self::VERSION end
14
+
15
+ def self.get_images
16
+ if Dir.exists? @default_directory
17
+ self.Delete_directory
18
+ else
19
+ Dir.mkdir(@default_directory)
20
+ end
21
+ (1..default_num).each{
22
+ o = [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten;
23
+ string = (0..10).map{ o[rand(o.length)] }.join;
24
+ image = HTTParty.get "http://robohash.org/#{string}.png"
25
+ open( "#{@default_directory}/#{string}.png", 'wb' ) { |file|
26
+ file.write(image.body)
27
+ }
28
+ }
29
+ end
30
+
31
+
32
+ private
33
+ def delete_directory
34
+ begin
35
+ Dir.delete(@default_directory)
36
+ rescue Exception => e
37
+ puts e.message
38
+ puts "You still want to delete? (Y/N)"
39
+ str = STDIN.getc.chr.downcase
40
+ if str == "y"
41
+ Dir.foreach(@default_directory) {|f|
42
+ if f == '.' or f == '..' then next
43
+ elsif File.directory?(f) then FileUtils.rm_rf("#{@default_directory}/#{f}")
44
+ else FileUtils.rm("#{@default_directory}/#{f}")
45
+ end
46
+ Dir.mkdir(@default_directory)
47
+ }
48
+ elsif str=="n"
49
+ exit
50
+ else
51
+ puts "Invalid parameter!"
52
+ exit
53
+ end
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,3 @@
1
+ module Robohash
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "robohash/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "robohash"
7
+ s.version = Robohash::VERSION
8
+ s.authors = ["xecutioner"]
9
+ s.email = ["xecutioner.kapil@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Robohash downloader}
12
+ s.description = %q{Downloads random robot images from robohash.org}
13
+ s.add_development_dependency "rspec"
14
+ s.add_development_dependency "httparty"
15
+ s.rubyforge_project = "robohash"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ describe Robohash do
3
+ it "Should return the correct version string" do
4
+ Robohash::VERSION.should == "0.0.1"
5
+ end
6
+
7
+ it "Should return the correct version " do
8
+ Robohash.Version.should == "0.0.1"
9
+ end
10
+
11
+ it "Should get the default number of images to download" do
12
+ Robohash.default_num.should eql(3)
13
+ end
14
+
15
+ it "Should set the default number of images to download" do
16
+ Robohash.default_num=150
17
+ Robohash.default_num.should eql(150)
18
+ end
19
+
20
+ it "Should get the default directory of images to download to" do
21
+ Robohash.default_directory.should eql("robo_hash_images")
22
+ end
23
+
24
+ it "Should set the default directory of images to download to" do
25
+ Robohash.default_directory="images/robots"
26
+ Robohash.default_directory.should eql("images/robots")
27
+ end
28
+
29
+ #it "Should download the default number of images to download to default directory" do
30
+ # Robohash.get_images
31
+ #Dir.exists?('robo_hash_images').should eql(true)
32
+ # end
33
+
34
+ end
35
+
@@ -0,0 +1,8 @@
1
+ require 'rspec'
2
+ require 'robohash'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ config.formatter = 'documentation'
7
+ end
8
+
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: robohash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - xecutioner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &83639610 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *83639610
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ requirement: &83639130 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *83639130
36
+ description: Downloads random robot images from robohash.org
37
+ email:
38
+ - xecutioner.kapil@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - README.md
46
+ - Rakefile
47
+ - lib/robohash.rb
48
+ - lib/robohash/version.rb
49
+ - robohash.gemspec
50
+ - spec/robohash_spec.rb
51
+ - spec/spec_helper.rb
52
+ homepage: ''
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project: robohash
72
+ rubygems_version: 1.8.10
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Robohash downloader
76
+ test_files: []