daily_menu 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/daily_menu/cli.rb +2 -24
- data/lib/daily_menu/version.rb +1 -1
- data/lib/daily_menu.rb +36 -0
- data/spec/daily_menu/cli_spec.rb +2 -2
- data/spec/daily_menu/restaurant_spec.rb +8 -1
- data/spec/daily_menu_spec.rb +58 -0
- metadata +2 -3
- data/lib/daily_menu/fetcher.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9dac4c4aefd8b0ae07213b067796b1b8549cb58
|
4
|
+
data.tar.gz: 29f79133826fda036006d8c1be180ce2c33507f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 171f24c7268b09c74f84229cde011492ec96e42cc6e623b0cadafe5bbc0cef3ff6de98dea8877af7fcfafaa34bea4d9f912ff74f1a0beb06f19f2f13d1c18bb7
|
7
|
+
data.tar.gz: 9954572fb0a09cf301e0585d8b66a821f2962c74a3c42575abcce14880f1c12c2d867172534dc596e196512e2115728b7b0e53a458543679b12009cc6ba20f38
|
data/lib/daily_menu/cli.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'yaml'
|
2
1
|
require 'awesome_print'
|
3
2
|
|
4
3
|
module DailyMenu
|
@@ -11,38 +10,17 @@ module DailyMenu
|
|
11
10
|
end
|
12
11
|
|
13
12
|
def self.fetch(location)
|
14
|
-
menus =
|
15
|
-
[restaurant.name, restaurant.menu]
|
16
|
-
end
|
17
|
-
|
13
|
+
menus = DailyMenu.menus_for(location)
|
18
14
|
Hash[menus]
|
19
15
|
end
|
20
16
|
private_class_method :fetch
|
21
17
|
|
22
18
|
def self.read_rc
|
23
|
-
raise 'Unable to read the config file' unless file_accessible?(RC_FILE)
|
19
|
+
raise 'Unable to read the config file' unless DailyMenu.file_accessible?(RC_FILE)
|
24
20
|
|
25
21
|
File.new(RC_FILE).read.chomp
|
26
22
|
end
|
27
23
|
private_class_method :read_rc
|
28
|
-
|
29
|
-
def self.restaurants_for_location(location)
|
30
|
-
configs_for_location(location).map { |config| Restaurant.from_hash(config) }
|
31
|
-
end
|
32
|
-
private_class_method :restaurants_for_location
|
33
|
-
|
34
|
-
def self.configs_for_location(location)
|
35
|
-
config_file = CONFIG_DIR.join("#{location}.yml")
|
36
|
-
raise %(No configuration found for: "#{location}") unless file_accessible?(config_file)
|
37
|
-
|
38
|
-
YAML.load_file(config_file)
|
39
|
-
end
|
40
|
-
private_class_method :configs_for_location
|
41
|
-
|
42
|
-
def self.file_accessible?(file)
|
43
|
-
File.exists?(file) && File.readable?(file)
|
44
|
-
end
|
45
|
-
private_class_method :file_accessible?
|
46
24
|
end
|
47
25
|
|
48
26
|
end
|
data/lib/daily_menu/version.rb
CHANGED
data/lib/daily_menu.rb
CHANGED
@@ -1,9 +1,45 @@
|
|
1
1
|
require 'daily_menu/version'
|
2
|
+
require 'yaml'
|
2
3
|
|
3
4
|
module DailyMenu
|
4
5
|
OAUTH_TOKEN = ENV['FACEBOOK_OAUTH_TOKEN'].freeze
|
5
6
|
ROOT = Pathname.new(File.expand_path('../..', __FILE__)).freeze
|
6
7
|
CONFIG_DIR = ROOT.join('configs').freeze
|
8
|
+
|
9
|
+
def self.menus_for(location)
|
10
|
+
restaurants = DailyMenu.restaurants_for(location)
|
11
|
+
|
12
|
+
menus = []
|
13
|
+
|
14
|
+
threads = restaurants.map do |restaurant|
|
15
|
+
Thread.new do
|
16
|
+
menus << [restaurant, restaurant.menu]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
threads.map(&:join)
|
21
|
+
|
22
|
+
menus
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.restaurants_for(location)
|
26
|
+
raise ArgumentError, 'Location needed' unless location
|
27
|
+
|
28
|
+
configs = config_for(location)
|
29
|
+
configs.map { |config| DailyMenu::Restaurant.from_hash(config) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.config_for(location)
|
33
|
+
config_file = CONFIG_DIR.join("#{location}.yml").to_s
|
34
|
+
raise %(No configuration found for: "#{location}") unless file_accessible?(config_file)
|
35
|
+
|
36
|
+
YAML.load_file(config_file)
|
37
|
+
end
|
38
|
+
private_class_method :config_for
|
39
|
+
|
40
|
+
def self.file_accessible?(file)
|
41
|
+
File.exists?(file) && File.readable?(file)
|
42
|
+
end
|
7
43
|
end
|
8
44
|
|
9
45
|
require 'daily_menu/entry'
|
data/spec/daily_menu/cli_spec.rb
CHANGED
@@ -15,9 +15,9 @@ module DailyMenu
|
|
15
15
|
it 'should read the rc file' do
|
16
16
|
rc_file = double('RC file', read: 'Foo/Bar')
|
17
17
|
|
18
|
-
|
18
|
+
DailyMenu.stub(:file_accessible?) { true }
|
19
19
|
File.stub(:new).with(described_class::RC_FILE) { rc_file }
|
20
|
-
|
20
|
+
DailyMenu.stub(:restaurants_for) { [] }
|
21
21
|
described_class.stub(:ap)
|
22
22
|
|
23
23
|
described_class.start([])
|
@@ -25,7 +25,14 @@ module DailyMenu
|
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'when there are fetched entries' do
|
28
|
-
let(:entries)
|
28
|
+
let(:entries) do
|
29
|
+
[
|
30
|
+
Entry.new('This is a menu entry', 2),
|
31
|
+
Entry.new('This is not', 1),
|
32
|
+
Entry.new('This is also a menu entry', 0)
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
29
36
|
before do
|
30
37
|
scraper.stub(:entries) { entries }
|
31
38
|
end
|
data/spec/daily_menu_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DailyMenu do
|
4
|
+
let(:location) { 'City/Area' }
|
5
|
+
|
4
6
|
describe 'ROOT' do
|
5
7
|
it 'should return the root path of the gem' do
|
6
8
|
expected_path = File.expand_path('..', File.dirname(__FILE__))
|
@@ -13,4 +15,60 @@ describe DailyMenu do
|
|
13
15
|
expect(described_class::VERSION).to_not be_nil
|
14
16
|
end
|
15
17
|
end
|
18
|
+
|
19
|
+
describe '.restaurants_for' do
|
20
|
+
it 'should raise an error when called with nil' do
|
21
|
+
expect { described_class.restaurants_for(nil) }.to raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should raise an error when the config file not found or not readable' do
|
25
|
+
expect { described_class.restaurants_for(location) }.to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should read the configuration file' do
|
29
|
+
described_class.stub(:file_accessible?) { true }
|
30
|
+
YAML.stub(:load_file) { [] }
|
31
|
+
|
32
|
+
described_class.restaurants_for(location)
|
33
|
+
|
34
|
+
expect(YAML).to have_received(:load_file).with(/City\/Area\.yml$/)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return with Restaruants' do
|
38
|
+
described_class.stub(:config_for) do
|
39
|
+
[{
|
40
|
+
name: 'Test',
|
41
|
+
scraper: { class: 'Facebook', params: '1', },
|
42
|
+
filter: { class: 'Hungarian' }
|
43
|
+
}]
|
44
|
+
end
|
45
|
+
|
46
|
+
restaurants = described_class.restaurants_for(location)
|
47
|
+
|
48
|
+
expect(restaurants).to have(1).restaurant
|
49
|
+
expect(restaurants[0]).to be_a(DailyMenu::Restaurant)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.menus_for' do
|
54
|
+
it 'should get the restaurants' do
|
55
|
+
described_class.stub(:restaurants_for) { [] }
|
56
|
+
|
57
|
+
described_class.menus_for(location)
|
58
|
+
|
59
|
+
expect(described_class).to have_received(:restaurants_for).with(location)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should return with correct items' do
|
63
|
+
menu = double('Menu')
|
64
|
+
restaurant = double('Restaurant', menu: menu)
|
65
|
+
described_class.stub(:restaurants_for) { [restaurant] }
|
66
|
+
|
67
|
+
menus = described_class.menus_for(location)
|
68
|
+
|
69
|
+
expect(menus).to have(1).menus
|
70
|
+
expect(menus).to include([restaurant, menu])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
16
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daily_menu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KARASZI István
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: koala
|
@@ -146,7 +146,6 @@ files:
|
|
146
146
|
- lib/daily_menu.rb
|
147
147
|
- lib/daily_menu/cli.rb
|
148
148
|
- lib/daily_menu/entry.rb
|
149
|
-
- lib/daily_menu/fetcher.rb
|
150
149
|
- lib/daily_menu/filters.rb
|
151
150
|
- lib/daily_menu/filters/hungarian.rb
|
152
151
|
- lib/daily_menu/filters/regexp.rb
|