micro_greens 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e1b17d8b82e8c72f3fd663aa616241319bc3f63
4
+ data.tar.gz: c677d4400ded1a33024f849b3ce1a361f8eda6b3
5
+ SHA512:
6
+ metadata.gz: 254457d51f607c0fd07e85e636bda96298e1d9550501c64840388a4d5ada1f57cdd9a1ae47d8eed0dbcc85f7885ab224b194b0352c61a5f975e26147f41195ea
7
+ data.tar.gz: a71615b378961b88b8e654f6c8fea225cce40253d20c647aae8a45f1d412088607cd89379f1dc7f2cbca0bb0fdd17b00c9ef64d9bc1eead0efae9670a7e948f9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at 'jmgsese@gmail.com'. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in micro_greens.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 'Joanna Sese'
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,36 @@
1
+ # MicroGreens::CLI::Gem
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'micro_greens'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install micro_greens
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/'jmgsese-93305'/micro_greens. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "micro_greens"
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(__FILE__)
data/bin/micro-greens ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/micro_greens'
4
+ MicroGreens::CLI.new.call
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'colorize'
5
+
6
+ require './lib/micro_greens/scraper.rb'
7
+ require './lib/micro_greens/version'
8
+ require './lib/micro_greens/cli'
@@ -0,0 +1,49 @@
1
+ #CLI controller
2
+
3
+ class MicroGreens::CLI
4
+
5
+ def scraper
6
+ @scraper = MicroGreens::Scraper.new
7
+ end
8
+
9
+ def call
10
+ puts "Who wants to eat some salad?".colorize(:green)
11
+ puts "Our most popular micro greens are:".colorize(:green)
12
+ scraper.list_greens
13
+ menu
14
+ goodbye
15
+ end
16
+
17
+ def html
18
+ Nokogiri::HTML(open("http://www.johnnyseeds.com/vegetables/micro-greens"))
19
+ end
20
+
21
+ def menu
22
+ puts "Type in the number corresponding to the micro green you would like to learn about.".colorize(:green)
23
+ puts "When you are done learning, type '0' to exit.".colorize(:green)
24
+ input = gets.to_i
25
+
26
+ if input <= 18 && input > 0
27
+ puts "Micro Green:".colorize(:green)
28
+ puts scraper.name(input)
29
+ puts "Description:".colorize(:green)
30
+ puts scraper.description_one(input)
31
+ puts scraper.description_two(input)
32
+ puts "Days to maturity:".colorize(:green)
33
+ puts scraper.maturity(input)
34
+ puts "Growing information:".colorize(:green)
35
+ puts scraper.grow_info(input)
36
+ menu
37
+ elsif input == 0
38
+ else
39
+ puts "Sorry, we do not have information about that micro green. Do try again!".colorize(:green)
40
+ menu
41
+ end
42
+
43
+ end
44
+
45
+ def goodbye
46
+ puts "Enjoy your salad!".colorize(:green)
47
+ end
48
+
49
+ end
@@ -0,0 +1,60 @@
1
+ class MicroGreens::Scraper
2
+ attr_accessor :name, :new_from_homepage, :description_one, :description_two, :maturity, :grow_info
3
+
4
+ def initialize(name=nil, new_from_homepage=nil)
5
+ @name = name
6
+ @new_from_homepage = new_from_homepage
7
+ end
8
+
9
+ #HOMEPAGE
10
+ def html
11
+ Nokogiri::HTML(open("http://www.johnnyseeds.com/vegetables/micro-greens"))
12
+ end
13
+
14
+ def homepage #main page with all micro-greens
15
+ doc = html.css("div#search-result-items")
16
+ micro_greens_tiles = Array.new
17
+ doc.css("div.o-layout__col").each do |tile|
18
+ name = tile.css("div.c-tile__col a.c-tile__link div.c-tile__name").text
19
+ link = tile.css("a").attribute("href").value.gsub("/vegetables/micro-greens","")
20
+ micro_greens_tiles << {name: name, link: link}
21
+ end
22
+ micro_greens_tiles
23
+ end
24
+
25
+ def list_greens #list of greens in alphabetical order, from homepage
26
+ homepage.sort_by{|hash| hash[:name]}.each.with_index do |hash, index|
27
+ puts "#{index+1}. #{hash[:name].strip}"
28
+ end
29
+ end
30
+
31
+ def select(input)
32
+ homepage.sort_by{|hash| hash[:name]}[input-1]
33
+ end
34
+
35
+ def name(input)
36
+ @name = select(input)[:name].strip
37
+ end
38
+
39
+ #INDIVIDUAL PROFILE PAGES
40
+ def new_from_homepage(input)
41
+ @new_from_homepage = Nokogiri::HTML(open("http://www.johnnyseeds.com#{select(input)[:link]}"))
42
+ end
43
+
44
+ def description_one(input)
45
+ @description_one = new_from_homepage(input).css("p.u-text-size-md").text
46
+ end
47
+
48
+ def description_two(input)
49
+ @description_two = new_from_homepage(input).css("div.c-content-toggle__content-wrapper").text.strip
50
+ end
51
+
52
+ def maturity(input)
53
+ @maturity = new_from_homepage(input).css("dd.c-facts__definition")[1].text.strip
54
+ end
55
+
56
+ def grow_info(input)
57
+ @grow_info = new_from_homepage(input).css("div.c-accordion__body span")[1].text
58
+ end
59
+
60
+ end
@@ -0,0 +1,3 @@
1
+ module MicroGreens
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+
2
+ module MicroGreens
3
+ end
4
+
5
+ require_relative '../config/environment'
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'micro_greens/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "micro_greens"
8
+ spec.version = MicroGreens::VERSION
9
+ spec.authors = ["'Joanna Sese'"]
10
+ spec.email = ["'jmgsese@gmail.com'"]
11
+
12
+ spec.summary = %q{Micro Greens}
13
+ spec.homepage = "https://github.com/joannasese/micro-greens-cli-app"
14
+ spec.license = "MIT"
15
+
16
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.14"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ end
data/spec.md ADDED
@@ -0,0 +1,6 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ - [x] Pull data from an external source
6
+ - [x] Implement both list and detail views
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: micro_greens
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Joanna Sese'"
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-30 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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:
42
+ email:
43
+ - "'jmgsese@gmail.com'"
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/micro-greens
56
+ - bin/setup
57
+ - config/environment.rb
58
+ - lib/micro_greens.rb
59
+ - lib/micro_greens/cli.rb
60
+ - lib/micro_greens/scraper.rb
61
+ - lib/micro_greens/version.rb
62
+ - micro_greens.gemspec
63
+ - spec.md
64
+ homepage: https://github.com/joannasese/micro-greens-cli-app
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.6.11
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Micro Greens
88
+ test_files: []