search_menu 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a9030ff93e3f3e5f2ddf729e66cfd4a17fea507
4
+ data.tar.gz: 36529ad72f1b741190df0a635855b9e79d0bd73f
5
+ SHA512:
6
+ metadata.gz: 36ef9e81d922f048287d7e8fc42d81fa3410ccbf3dc5cdd01272b5ce837212d2196ee2a891ccdb9954d44ec905638c562e270c40014ba15de84ab930fb54f954
7
+ data.tar.gz: 5d1c5ee5dfbf816e56acb1590598b4a4fbe2cbc3810bbd58be547ea630bf0bc2b580e6a8e65591b027d8918cc6c03aef80e16586e71eb964ab0dc587a0226d5b
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in search_menu.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Scott
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # SearchMenu
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/search_menu`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'search_menu'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install search_menu
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/search_menu/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "search_menu"
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
data/bin/search_menu ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require "search_menu"
7
+ require 'optparse'
8
+
9
+ options = {}
10
+
11
+ optparse = OptionParser.new do |opts|
12
+ opts.banner = "Usage: search_menu.rb [options] file1 file2 etc.."
13
+ end
14
+ optparse.parse!
15
+
16
+ if ARGV.empty?
17
+ puts optparse
18
+ exit(-1)
19
+ end
20
+
21
+ ARGV.each do|f|
22
+ menu = SearchMenu.new
23
+ menu.get_file_or_data(f)
24
+ end
data/bin/setup ADDED
@@ -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
data/lib/core_ext.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'search_menu'
2
+ require 'search_menu/core_ext/array'
@@ -0,0 +1,51 @@
1
+ require "search_menu/version"
2
+
3
+ class SearchMenu
4
+
5
+ attr_accessor :file_name, :price_goal, :menu_items, :winning_combo
6
+
7
+ def initialize(input = nil)
8
+ @file_name = ""
9
+ @price_goal = ""
10
+ @menu_items = []
11
+ get_file_or_data(input) if input
12
+ end
13
+
14
+ def get_file_or_data(input)
15
+ data = File.read(input).scan(/[,$]+(\d+\.\d+)|(.*\b)[,$]+(\d+\.\d+)/).each{ |scn| scn.compact! }
16
+ @file_name = input
17
+ @price_goal = data[0]
18
+ @menu_items = menu_to_hash(data[2, data.size])
19
+ find_target_price
20
+ end
21
+ # superfluous for now. perhaps a refactor
22
+ # def price_goal_to_number(price_goal)
23
+ # price_goal.flatten.collect { |i| i.to_f }
24
+ # end
25
+
26
+ def hash_input(data)
27
+ data = data.collect { |k, v| [k, v]}.each{ |s| s.compact! }
28
+ scrub_data(data)
29
+ end
30
+
31
+ def menu_to_hash(menu_prices)
32
+ menu_prices.map { |menu_item, item_cost| {menu_item: menu_item, item_cost: item_cost} }
33
+ end
34
+
35
+ def find_target_price(*data)
36
+ # look into why this is needed
37
+ @winning_combo = []
38
+ 1.upto(@menu_items.length).each{ |i| @menu_items.combination(i).each { |j|
39
+ @winning_combo << j if j.map{|x| x[:item_cost].to_f}.inject(:+) == @price_goal[0].to_f}}
40
+ eat_or_starve
41
+ end
42
+
43
+ def eat_or_starve
44
+ decision = []
45
+ decision << [file_name: "#{@file_name}"]
46
+ @winning_combo.empty? ? decision << [{sorry: "Sorry, there are no combination of dishes that will be equal in cost to your target price"}] : decision << @winning_combo
47
+ decision.flatten!
48
+ decision
49
+ end
50
+
51
+ end
@@ -0,0 +1,2 @@
1
+ require "search_menu"
2
+ require 'search_menu/core_ext'
@@ -0,0 +1,7 @@
1
+ require 'search_menu'
2
+
3
+ class Array
4
+ def search_menu
5
+ SearchMenu.new.find_target_price(self)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'search_menu'
2
+
3
+ class Hash
4
+ def search_menu
5
+ SearchMenu.new.hash_input(self)
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SearchMenu
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'search_menu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "search_menu"
8
+ spec.version = SearchMenu::VERSION
9
+ spec.authors = ["Scott"]
10
+ spec.email = ["scott@dottedt.com"]
11
+
12
+ if spec.respond_to?(:metadata)
13
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
14
+ end
15
+
16
+ spec.summary = %q{Finds combinations of dishes by fixed price.}
17
+ spec.description = %q{Finds any combination of dishes that add up exactly to the target price.}
18
+ spec.homepage = "https://github.com/dottedt/search_menu.git"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.8"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: search_menu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Scott
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-02-27 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.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
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: Finds any combination of dishes that add up exactly to the target price.
42
+ email:
43
+ - scott@dottedt.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/search_menu
56
+ - bin/setup
57
+ - lib/core_ext.rb
58
+ - lib/search_menu.rb
59
+ - lib/search_menu/all.rb
60
+ - lib/search_menu/core_ext/array.rb
61
+ - lib/search_menu/core_ext/hash.rb
62
+ - lib/search_menu/version.rb
63
+ - search_menu.gemspec
64
+ homepage: https://github.com/dottedt/search_menu.git
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ allowed_push_host: https://rubygems.org
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.6
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Finds combinations of dishes by fixed price.
89
+ test_files: []