image_listing 0.0.2
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.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +14 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +10 -0
- data/image_listing-0.0.1.gem +0 -0
- data/image_listing.gemspec +23 -0
- data/lib/.DS_Store +0 -0
- data/lib/image_listing.rb +70 -0
- data/lib/image_listing/version.rb +3 -0
- data/test/test_helper.rb +9 -0
- data/test/unit/image_listing_test.rb +22 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 59bc92b62f7321ff41c9d49d0b6d6108e81b1c8f
|
4
|
+
data.tar.gz: 934177ac633f9be9cc64d73f9a3fd21901ba098b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9703279182468f5562ae9db10b715230de2d8f8f19539d4911037bedb0e467d84866779111a90c6df5f61160930c435e58a6fd31b07e28e59542527c329c2ce0
|
7
|
+
data.tar.gz: fbee317b00991cb7ef0912e78e5a01eb5d30c7c39c3a935884456dae1fc60f03776fba1e1bee8a5f998d096d9bab7505c87f79b26dccf699dfb1fa8ba2976adc
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 anthony
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# ImageListing
|
2
|
+
|
3
|
+
|
4
|
+
Image finder goes to the given web page and gets a list of largest images(by screen real estate each image taken; width x height) on that page
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'image_listing'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install image_listing
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
require 'image_listing'
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( https://github.com/iamfree-com/image_listing/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'image_listing/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "image_listing"
|
8
|
+
spec.version = ImageListing::VERSION
|
9
|
+
spec.authors = ["anthony"]
|
10
|
+
spec.email = ["anthony@iamfree.com"]
|
11
|
+
spec.summary = %q{Gets a list of largest images from a web page}
|
12
|
+
spec.description = %q{Image finder goes to the given web page and gets a list of largest images on that page}
|
13
|
+
spec.homepage = %q{https://github.com/iamfree-com/image_listing}
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative "image_listing/version"
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'mechanize'
|
5
|
+
require 'fastimage'
|
6
|
+
module ImageListing
|
7
|
+
|
8
|
+
class ImageListing
|
9
|
+
#URL = "http://iamfree.com"
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@mech = Mechanize.new
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def show_list_of_images(url)
|
17
|
+
Mechanize.new.get(url) {|page| puts page.image_urls.join "\n"}
|
18
|
+
end
|
19
|
+
|
20
|
+
def list_of_images(url)
|
21
|
+
page = @mech.get(url)
|
22
|
+
|
23
|
+
a = []
|
24
|
+
page.image_urls.each do |o|
|
25
|
+
a << o.to_s
|
26
|
+
end
|
27
|
+
a
|
28
|
+
# a = {}
|
29
|
+
# (page.image_urls.first.methods - Object.methods).each do |m|
|
30
|
+
# begin
|
31
|
+
# a[m.to_s] = page.image_urls.first.send(m.to_s).to_s
|
32
|
+
# rescue
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
# a
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
def get_the_sizes_of_images(url)
|
41
|
+
lit = list_of_images(url)
|
42
|
+
a = []
|
43
|
+
lit.each do |img|
|
44
|
+
a << ( FastImage.size(img) << img )
|
45
|
+
end
|
46
|
+
list = a.sort {|x,y| y[0] <=> x[0]}
|
47
|
+
list_sorted = a.sort {|x,y| y[1] <=> x[1]}
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_the_sizes_of_images_limited(url, n)
|
52
|
+
lit = list_of_images(url)
|
53
|
+
a = []
|
54
|
+
lit.each do |img|
|
55
|
+
the_size = FastImage.size(img)
|
56
|
+
#get the images screen realestate in pixels
|
57
|
+
width_by_height = the_size[0] * the_size[1]
|
58
|
+
addimage = (the_size << img)
|
59
|
+
a << (addimage << width_by_height)
|
60
|
+
end
|
61
|
+
list =a.sort {|x,y| y[3] <=> x[3]}
|
62
|
+
list.first(n)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
#p ImageListing.new.get_the_sizes_of_images_limited("http://iamfree.com", 5)
|
69
|
+
|
70
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
|
2
|
+
class ImageListingTest < Minitest::Test
|
3
|
+
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@image_list = ImageListing::ImageListing.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_for_array
|
10
|
+
array = @image_list.get_the_sizes_of_images("http://iamfree.com" )
|
11
|
+
assert_instance_of Array , array
|
12
|
+
assert array.count > 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_get_the_sizes_of_images_limited
|
16
|
+
array = @image_list.get_the_sizes_of_images_limited("http://iamfree.com", 5)
|
17
|
+
assert_instance_of Array , array
|
18
|
+
assert_equal array.count, 5
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: image_listing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- anthony
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Image finder goes to the given web page and gets a list of largest images
|
42
|
+
on that page
|
43
|
+
email:
|
44
|
+
- anthony@iamfree.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".DS_Store"
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- image_listing-0.0.1.gem
|
56
|
+
- image_listing.gemspec
|
57
|
+
- lib/.DS_Store
|
58
|
+
- lib/image_listing.rb
|
59
|
+
- lib/image_listing/version.rb
|
60
|
+
- test/test_helper.rb
|
61
|
+
- test/unit/image_listing_test.rb
|
62
|
+
homepage: https://github.com/iamfree-com/image_listing
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.2.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Gets a list of largest images from a web page
|
86
|
+
test_files:
|
87
|
+
- test/test_helper.rb
|
88
|
+
- test/unit/image_listing_test.rb
|