smart_aleck 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTIwMTIyMmFiNWQyYzg1NTk4MWM1NWI1ZjQ0NzJiYzU2MmI3ZWU5MA==
5
+ data.tar.gz: !binary |-
6
+ OTYxZTg4YTVmODRhOTBjNzU4ZWRjZDJjZWI3ODEyMzRjMDdiNTIwZg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YzM1M2FjZDk4ZDJiZDIyMzA5MzgxZDQ0NjI0MjQ5YjJmODlkYjZmOGU5ZjQ3
10
+ NTUyMWQyMmRkYTlmZjg5ODYwMDg0NmU1ZjgwOWExYWQxOTc1NjdlMGQ0MWI2
11
+ N2MyYWY1ZGM2MjA1NzJmMWJjZTVmMGViNWMyNjY1ZjE0MWU1Zjc=
12
+ data.tar.gz: !binary |-
13
+ NjQ5ZjUwMThhNmU2M2ZlOTkxODUwYWNhMTk1MDU0Njg4ZjdkMzVhZTA5MmRl
14
+ ZTBjOGU5NTQ4NGNmYTY4MzZmMTE2YWViYzgxNTA4MjRhNTM4NjY3ZGJlYmUz
15
+ NGI3ZTEwOWUyMGE1MjY5NmE2MjMyMTQ2NjYxNDgyNmY2ZjViMjI=
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smart_aleck.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Dennis Walters
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ # SmartAleck
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'smart_aleck'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install smart_aleck
18
+
19
+ ## Usage
20
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "smart_aleck"
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,35 @@
1
+ require "optionally"
2
+ require "smart_aleck/version"
3
+ require 'smart_aleck/category_indexer'
4
+ require 'smart_aleck/entry_creator'
5
+ require 'smart_aleck/finding_viable_peers'
6
+
7
+ module SmartAleck
8
+ include Optionally::Required
9
+
10
+ def self.configure(options)
11
+ check_required_options(options, :category_model, :entry_model)
12
+ @category_model = options[:category_model]
13
+ @entry_model = options[:entry_model]
14
+ end
15
+
16
+ def self.category_model
17
+ @category_model
18
+ end
19
+
20
+ def self.entry_model
21
+ @entry_model
22
+ end
23
+
24
+ def self.verify_configured
25
+ raise NotConfigured unless (category_model && entry_model)
26
+ true
27
+ end
28
+
29
+ def self.clear_config!
30
+ @entry_model = @category_model = nil
31
+ end
32
+
33
+ class NotConfigured < StandardError
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ module SmartAleck
2
+ class CategoryIndexer
3
+ attr_reader :category_hash
4
+
5
+ def self.index(categories)
6
+ new(categories).category_hash
7
+ end
8
+
9
+ def initialize(categories)
10
+ @category_hash =
11
+ categories.map {|category|
12
+ 2 ** (category.respond_to?(:id) ? category.id : category).to_i
13
+ }.inject(:|).to_i
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,41 @@
1
+ require 'optionally/required'
2
+ require_relative '../smart_aleck/category_indexer'
3
+
4
+ module SmartAleck
5
+ class EntryCreator
6
+ include Optionally::Required
7
+
8
+ attr_reader :entry
9
+
10
+ def self.create(options = {})
11
+ new(options).entry
12
+ end
13
+
14
+ def initialize(options = {})
15
+ SmartAleck.verify_configured
16
+ check_required_options(options, :title, :content, :categories, :user)
17
+ @title = options[:title]
18
+ @content = options[:content]
19
+ @categories = options[:categories]
20
+ @user = options[:user]
21
+ populate_entry
22
+ categorize_entry
23
+ end
24
+
25
+ private
26
+ def populate_entry
27
+ @entry = SmartAleck.entry_model.create(
28
+ title: @title,
29
+ content: @content,
30
+ category_hash: CategoryIndexer.index(@categories),
31
+ user: @user
32
+ )
33
+ end
34
+
35
+ def categorize_entry
36
+ @categories.each do |category|
37
+ @entry.add_category(category)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ module SmartAleck
2
+ class FindingViablePeers
3
+ attr_reader :categories
4
+
5
+ def initialize(categories = [])
6
+ @categories = categories
7
+ end
8
+
9
+ def viable_peers
10
+ return SmartAleck.category_model.with_entries if categories.empty?
11
+ categories.
12
+ map(&:entries).
13
+ flatten.
14
+ uniq.
15
+ select {|entry| (categories.map(&:id) - entry.category_ids).empty?}.
16
+ map(&:categories).
17
+ flatten.
18
+ uniq - categories
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module SmartAleck
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smart_aleck/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smart_aleck"
8
+ spec.version = SmartAleck::VERSION
9
+ spec.authors = ["Dennis Walters"]
10
+ spec.email = ["pooster@gmail.com"]
11
+
12
+ spec.summary = %q{A know-it-all categorization system}
13
+ spec.homepage = "https://github.com/ess/smart_aleck"
14
+ spec.license = "MIT"
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 "rspec", "~> 3.2"
24
+ spec.add_development_dependency "faker", "~> 1.4"
25
+ spec.add_runtime_dependency "optionally"
26
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_aleck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dennis Walters
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-08 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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faker
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: optionally
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - pooster@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/smart_aleck.rb
100
+ - lib/smart_aleck/category_indexer.rb
101
+ - lib/smart_aleck/entry_creator.rb
102
+ - lib/smart_aleck/finding_viable_peers.rb
103
+ - lib/smart_aleck/version.rb
104
+ - smart_aleck.gemspec
105
+ homepage: https://github.com/ess/smart_aleck
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.5
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A know-it-all categorization system
129
+ test_files: []