nyc-farmers-markets 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/nyc-farmers-markets +5 -0
- data/config/environment.rb +10 -0
- data/lib/nyc_farmers_markets/cli.rb +93 -0
- data/lib/nyc_farmers_markets/get_markets.rb +14 -0
- data/lib/nyc_farmers_markets/market.rb +77 -0
- data/lib/nyc_farmers_markets.rb +4 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4b6db991e901454deca9b32543ee3ca7abb54a45
|
4
|
+
data.tar.gz: fddb301656fd30952eaa5237a437f24c02607b4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d9a5f337a1ad41efcdf95ac0978cea9c62ff9eaf1d79c33593186bdd8c581e5f5338792e5380a51e51e19af99b4b20eb9f8583d64ea1b5e92fbcbcf99d67689
|
7
|
+
data.tar.gz: 5eaedc72b129739726e93bfd09737f7f708aab824db489b945556fe8d7bf64d8d945d79646bb2951b0c6d4f347a9f458023efb8fbb8ff7cd108a1d963bdcf5f1
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'json'
|
3
|
+
#require 'open-uri'
|
4
|
+
require 'open-uri/cached'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
|
8
|
+
require_relative '../lib/nyc_farmers_markets/cli'
|
9
|
+
require_relative '../lib/nyc_farmers_markets/get_markets'
|
10
|
+
require_relative '../lib/nyc_farmers_markets/market'
|
@@ -0,0 +1,93 @@
|
|
1
|
+
class NYCFarmersMarkets::CLI
|
2
|
+
|
3
|
+
def call
|
4
|
+
NYCFarmersMarkets::GetMarkets.new.make_markets
|
5
|
+
vesta = "\u26B6".encode('utf-8')
|
6
|
+
flower = "\u2698".encode('utf-8')
|
7
|
+
puts "\n\t #{vesta} Welcome to the Farmers Markets of NYC #{vesta} ".green.underline
|
8
|
+
print "\t"; 15.times { print "#{flower} ".light_blue }; puts ""
|
9
|
+
|
10
|
+
start
|
11
|
+
end
|
12
|
+
|
13
|
+
def start
|
14
|
+
loop do
|
15
|
+
print "\nWhat would you like to do (type help for more info)? "
|
16
|
+
|
17
|
+
input = gets.chomp.downcase
|
18
|
+
|
19
|
+
case input
|
20
|
+
when "list all"
|
21
|
+
list_all
|
22
|
+
when "list boroughs"
|
23
|
+
#puts market_set.list_boroughs.join(" - ")
|
24
|
+
list_boroughs
|
25
|
+
when "bronx", "brooklyn", "manhattan", "queens", "staten island"
|
26
|
+
print_by_borough(input)
|
27
|
+
when "list zip codes"
|
28
|
+
puts market_set.list_zipcodes.join(" - ")
|
29
|
+
when *market_set.list_zipcodes
|
30
|
+
print_by_zipcode(input)
|
31
|
+
when "help"
|
32
|
+
help
|
33
|
+
when "exit"
|
34
|
+
puts "See you next time!"
|
35
|
+
break
|
36
|
+
else
|
37
|
+
puts "Invalid selection!".red
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def print_by_borough(borough)
|
43
|
+
market_set.find_by_borough(borough).each do |m|
|
44
|
+
puts "\n#{m.name}".green
|
45
|
+
puts "#{m.street_address}, #{m.borough}, #{m.zipcode}"
|
46
|
+
puts "#{m.additional_info}" unless m.additional_info == nil
|
47
|
+
puts "#{m.website}" unless m.website == nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def print_by_zipcode(zipcode)
|
52
|
+
market_set.find_by_zipcode(zipcode).each do |m|
|
53
|
+
puts "\n#{m.name}".green
|
54
|
+
puts "#{m.street_address}, #{m.borough}, #{m.zipcode}"
|
55
|
+
puts "#{m.additional_info}" unless m.additional_info == nil
|
56
|
+
puts "#{m.website}" unless m.website == nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def list_all
|
61
|
+
market_set.all.each do |m|
|
62
|
+
puts "\n#{m.name}".green
|
63
|
+
puts m.street_address == nil ? "-address not available-" : "#{m.street_address}, #{m.borough}, #{m.zipcode}"
|
64
|
+
puts "#{m.additional_info}" unless m.additional_info == nil
|
65
|
+
puts "#{m.website}" unless m.website == nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def list_boroughs
|
70
|
+
puts "\n\tBoroughs and Their Number of Farmers Markets".green
|
71
|
+
boroughs_with_num_markets = market_set.list_boroughs.collect do |b|
|
72
|
+
"#{b}(#{market_set.num_markets_in_borough(b)})"
|
73
|
+
end
|
74
|
+
puts boroughs_with_num_markets.join(", ")
|
75
|
+
end
|
76
|
+
|
77
|
+
def help
|
78
|
+
hand = "\u261E".encode('utf-8')
|
79
|
+
keyboard = "\u2328".encode('utf-8')
|
80
|
+
puts "\n #{keyboard} These are the available commands #{keyboard}".light_blue.underline
|
81
|
+
puts "#{hand}list all\t-See a list of all Farmers Markets"
|
82
|
+
puts "#{hand}list boroughs -See a list of boroughs with Farmers Markets"
|
83
|
+
puts "#{hand}[borough name] -See all markets in this borough"
|
84
|
+
puts "#{hand}list zip codes -See a list of zip codes"
|
85
|
+
puts "#{hand}[zip code]\t-See all markets in this zip code"
|
86
|
+
puts "#{hand}help\t\t-See this helpful list of commands!"
|
87
|
+
puts "#{hand}exit\t\t-Say good-bye"
|
88
|
+
end
|
89
|
+
|
90
|
+
def market_set
|
91
|
+
NYCFarmersMarkets::Market
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class NYCFarmersMarkets::GetMarkets
|
2
|
+
URL = "https://data.cityofnewyork.us/resource/cw3p-q2v6.json"
|
3
|
+
|
4
|
+
def get_markets
|
5
|
+
content = open(URL).read
|
6
|
+
markets = JSON.parse(content)
|
7
|
+
end
|
8
|
+
|
9
|
+
def make_markets
|
10
|
+
get_markets.each do |market_hash|
|
11
|
+
NYCFarmersMarkets::Market.create_from_hash(market_hash)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class NYCFarmersMarkets::Market
|
2
|
+
attr_accessor :name, :additional_info, :street_address, :borough, :state, :zipcode, :latitude, :longitude, :website
|
3
|
+
|
4
|
+
@@all = []
|
5
|
+
|
6
|
+
def initialize(name: nil, additional_info: nil, street_address: nil, borough: nil, state: "NY", zipcode: nil, website: nil)
|
7
|
+
@name = name
|
8
|
+
@additional_info = additional_info
|
9
|
+
@street_address = street_address
|
10
|
+
@borough = borough
|
11
|
+
@state = state
|
12
|
+
@zipcode = zipcode
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.all
|
16
|
+
@@all
|
17
|
+
end
|
18
|
+
|
19
|
+
def save
|
20
|
+
@@all << self
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.create_from_hash(h)
|
24
|
+
market = self.new(
|
25
|
+
name: h["facilityname"],
|
26
|
+
additional_info: h["facilityaddinfo"],
|
27
|
+
street_address: h["facilitystreetname"],
|
28
|
+
borough: h["facilitycity"],
|
29
|
+
state: h["facilitystate"],
|
30
|
+
zipcode: h["facilityzipcode"]
|
31
|
+
)
|
32
|
+
|
33
|
+
market.set_website_from_additional_info
|
34
|
+
market.remove_html
|
35
|
+
market.save
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_website_from_additional_info
|
39
|
+
if @additional_info != nil
|
40
|
+
url_from_info = @additional_info.match(/http:(\w|\/|\.|\&|\=|\?|\_)*</)
|
41
|
+
@website = url_from_info[0].chomp("<").chomp(".") unless url_from_info == nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def remove_html
|
46
|
+
if @additional_info != nil && @additional_info.include?("<")
|
47
|
+
x = @additional_info.index("<")
|
48
|
+
y = @additional_info.length - 1
|
49
|
+
@additional_info.slice!(x..y)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.find_by_borough(b)
|
55
|
+
self.all.select do |market|
|
56
|
+
market if market.borough != nil && market.borough.downcase == b.downcase
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.find_by_zipcode(z)
|
61
|
+
self.all.select do |market|
|
62
|
+
market if market.zipcode == z
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.list_boroughs
|
67
|
+
self.all.collect { |market| market.borough }.compact.uniq.sort
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.list_zipcodes
|
71
|
+
self.all.collect { |market| market.zipcode }.compact.uniq.sort
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.num_markets_in_borough(b)
|
75
|
+
self.find_by_borough(b).count
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nyc-farmers-markets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin McCormack
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: open-uri-cached
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.5
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A Ruby gem for the NYC Farmers Markets API with a CLI
|
70
|
+
email: wittyman37@yahoo.com
|
71
|
+
executables:
|
72
|
+
- nyc-farmers-markets
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- bin/nyc-farmers-markets
|
77
|
+
- config/environment.rb
|
78
|
+
- lib/nyc_farmers_markets.rb
|
79
|
+
- lib/nyc_farmers_markets/cli.rb
|
80
|
+
- lib/nyc_farmers_markets/get_markets.rb
|
81
|
+
- lib/nyc_farmers_markets/market.rb
|
82
|
+
homepage: https://github.com/HarlemSquirrel/nyc-farmers-markets-cli-gem
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.4.5
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Wrapper and CLI the NYC Farmers Markets API
|
106
|
+
test_files: []
|