ffffound_parser 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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70f1d9032011163a41964bacb1713feacbb96798
4
+ data.tar.gz: 46a21a0e7d0158d8b24c238e7d2e7c5826042baa
5
+ SHA512:
6
+ metadata.gz: bdd1c01ce23a0d23a3d98b59c7d900bc94849487e6942f2def08908f6dc2b63c7c78cf4db77bb4c898fe457c894f78c0d55fc35b2d03b2540c413eb355a4a5cd
7
+ data.tar.gz: 7d11a33c74da0fd354a31a8ad163b9c70fd8a62a150d8e7de6244415372f9bb610e64c2a24ea48d9fcc47a4a39d401017222981bf15815ec4d4c4d2819cb883c
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
11
+
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ffffound_parser.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rspec'
8
+ end
@@ -0,0 +1,41 @@
1
+ # FfffoundParser
2
+
3
+ Simple parser for grabing images from ffffound.com
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ffffound_parser'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ FfffoundParser.find(PAGE_NUMBER)
21
+ #=> #<FfffoundParser::Parser:0x007f7f06801bf0
22
+ @image_list=
23
+ [#<struct Struct::Image link="25.media.tumblr.com/tumblr_le9kfgSmA81qb5tu1o1_500.gif", posted_at="2015-06-26 02:15:25">,
24
+ #<struct Struct::Image link="24.media.tumblr.com/ddaf5101cb946501dbbcfb1387248fa7/tumblr_n35rnjzzXJ1twnn02o1_500.jpg", posted_at="2015-06-25 17:49:12">,
25
+ <...>
26
+ @page_number=1>
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/[my-github-username]/ffffound_parser/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ffffound_parser'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ffffound_parser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.licenses = ['MIT']
8
+ spec.name = 'ffffound_parser'
9
+ spec.version = FfffoundParser::VERSION
10
+ spec.authors = ['Emil Shakirov']
11
+ spec.email = ['5o.smoker@gmail.com']
12
+ spec.homepage = 'https://github.com/vaihtovirta/ffffound_parser'
13
+
14
+ spec.summary = 'Simple parser for grabing images from ffffound.com'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.9'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'nokogiri', '~> 1.6'
24
+ spec.add_development_dependency 'time-lord', '~> 1.0'
25
+ end
@@ -0,0 +1,17 @@
1
+ require 'ffffound_parser/version'
2
+ require 'ffffound_parser/parser'
3
+
4
+ module FfffoundParser
5
+ class PageNumberError < StandardError; end
6
+
7
+ def self.find(page_number)
8
+ fail PageNumberError, 'Page number is invalid' unless page_number_valid?(page_number)
9
+ Parser.new(page_number)
10
+ end
11
+
12
+ private
13
+
14
+ def self.page_number_valid?(page_number)
15
+ page_number > 0 && page_number.is_a?(Integer)
16
+ end
17
+ end
@@ -0,0 +1,52 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ module FfffoundParser
5
+ class Parser
6
+ SITE_LINK = 'http://ffffound.com/?offset='
7
+ DATE_WORD_REGEXP = /(\s?(\d+)\s(hours|minutes|days))+\s(ago)/
8
+ DATE_NUMBERS_REGEXP = /(\d+\s\w+)/i
9
+
10
+ attr_reader :image_list
11
+
12
+ def initialize(page_number = 1)
13
+ @page_number = page_number
14
+ Struct.new('Image', :link, :posted_at)
15
+ @image_list = parse(target_page)
16
+ end
17
+
18
+ private
19
+
20
+ def parse(page)
21
+ page.css('blockquote.asset').map do |block|
22
+ info = info(block.css('.description'))
23
+ image_src = info[0]
24
+ date = info[1]
25
+ date = date_decorate(date)
26
+ Struct::Image.new(image_src, date)
27
+ end
28
+ end
29
+
30
+ def date_decorate(date)
31
+ date.match(DATE_WORD_REGEXP) ? words_to_date(date.scan(DATE_NUMBERS_REGEXP).flatten) : date
32
+ end
33
+
34
+ def info(nodes)
35
+ return unless nodes
36
+ nodes.map { |node| node.children.map(&:text) }
37
+ .flatten
38
+ .reject(&:empty?)
39
+ .map(&:strip)
40
+ end
41
+
42
+ def words_to_date(words)
43
+ words.each_slice(2) do |num, word|
44
+ Time.now - num.send(word)
45
+ end
46
+ end
47
+
48
+ def target_page
49
+ Nokogiri::HTML(open("#{SITE_LINK}#{@page_number * 25}"))
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module FfffoundParser
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffffound_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Emil Shakirov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-13 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: time-lord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ description:
70
+ email:
71
+ - 5o.smoker@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - ffffound_parser.gemspec
84
+ - lib/ffffound_parser.rb
85
+ - lib/ffffound_parser/parser.rb
86
+ - lib/ffffound_parser/version.rb
87
+ homepage: https://github.com/vaihtovirta/ffffound_parser
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.5
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Simple parser for grabing images from ffffound.com
111
+ test_files: []