landmarks-of-st-petersburg 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8fe69baa2c65023398a291135a8a53600f7e3075
4
+ data.tar.gz: 6154934acb24c6a64acb2da3e579dfc4ea0eb503
5
+ SHA512:
6
+ metadata.gz: bd03b63df1d031f60f177ad4af3686d73c4d5d4373cea97144519d8fe7db293ae332fb51f58dd6735aa23ed68e06fdfacb6984231bdc31d0552cc15fd5d18bcf
7
+ data.tar.gz: 529a34075963a8ee57cb14514932869be99d90b6f4cb5dd16185aad8d61187503ada5a9c327d427f2b3aa1c1dd36cb63d4a56549283378c7956996ff50fb2a87
@@ -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 'eskinhd@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,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pry'
4
+ gem 'require_all'
5
+ gem 'nokogiri'
6
+
7
+ # Specify your gem's dependencies in landmarks.gemspec
8
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 'Igor Eskin'
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,39 @@
1
+ # Landmarks of St. Petersburg
2
+
3
+ This Ruby Gem provides a CLI to view the top 20 architectural landmarks of St. Petersburg with detailed description and other useful information.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'landmarks-of-st-petersburg'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install landmarks-of-st-petersburg
20
+
21
+ ## Usage
22
+
23
+ To run this gem as a local application, please run ./bin/landmarks from the command line.
24
+ If you have already installed the gem, please enter landmarks in the command line and follow the on-screen prompts.
25
+
26
+ ## Development
27
+
28
+ 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.
29
+
30
+ 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).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/igoreskin/landmarks-of-st-petersburg-cli-app. 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.
35
+
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "landmarks"
5
+
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/landmarks'
4
+
5
+ Landmarks::CLI.new.call
@@ -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,9 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ require_relative '../lib/landmarks/scraper'
6
+ require_relative '../lib/landmarks/landmark'
7
+ require_relative '../lib/landmarks/cli'
8
+
9
+ # require_all 'lib'
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'landmarks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "landmarks-of-st-petersburg"
8
+ spec.version = Landmarks::VERSION
9
+ spec.authors = ["'Igor Eskin'"]
10
+ spec.email = ["'eskinhd@gmail.com'"]
11
+
12
+ spec.summary = %q{Top 20 architectural landmarks of St. Petersburg with descriptions and other useful information.}
13
+ spec.description = %q{This gem allows to scrape a website of top 20 architectural attractions of St. Petersburg, Russia,
14
+ and by the user's choice display an eloquent description of each individual attraction as well as some useful details (if available),
15
+ such as location, directions, names of other attractions located nearby, business hours and possible admission fee.}
16
+ spec.homepage = "https://github.com/igoreskin/landmarks-of-st-petersburg-cli-app"
17
+ spec.license = "MIT"
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ =begin
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+ =end
29
+
30
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
31
+ f.match(%r{^(test|spec|features)/})
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.14"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ end
@@ -0,0 +1,8 @@
1
+ require_relative "../lib/landmarks/version"
2
+
3
+ module Landmarks
4
+
5
+ end
6
+
7
+
8
+ require_relative '../config/environment'
@@ -0,0 +1,71 @@
1
+ class Landmarks::CLI
2
+
3
+ def call
4
+ puts ""
5
+ puts "WELCOME TO TOP 20 ST. PETERSBURG ARCHITECTURAL LANDMARKS!"
6
+ scraper = Landmarks::Landmark.scraper
7
+ scraper.print_the_title
8
+ scraper.scrape_landmarks_index
9
+ puts ""
10
+ scraper.print_landmarks_index
11
+ puts ""
12
+ start
13
+ end
14
+
15
+ def start
16
+ puts "Please enter the number of the landmark you would like more information on:"
17
+ input = gets.chomp.to_i
18
+ if !input.between?(1, 20)
19
+ puts "Please enter a number from 1 to 20!"
20
+ start
21
+ end
22
+ landmark = Landmarks::Landmark.find(input)
23
+ puts "\t\n"
24
+ puts landmark.name.strip.upcase
25
+ puts "\t\n"
26
+ puts "\t\t\t\t\t\t================== Description of the Landmark =================="
27
+ puts "\t\n"
28
+ puts landmark.description
29
+ puts "\t\n"
30
+ puts "\t\t\t\t\t\t================================================================="
31
+ puts "\t\n"
32
+ puts "Would you like to check the availability of directions, contact information and business hours? y/n"
33
+ answer = gets.chomp.downcase
34
+
35
+ if answer == "y"
36
+ puts "\t\n"
37
+ puts "\t\t\t\t\t\t====== Directions, contact information and business hours ======"
38
+ puts "\t\n"
39
+ puts landmark.directions
40
+ puts "\t\n"
41
+ puts "\t\t\t\t\t\t================================================================="
42
+ puts "\t\n"
43
+ puts "Would you like to find out more about another landmark? y/n"
44
+ response = gets.chomp.downcase
45
+
46
+ if response == "y"
47
+ start
48
+ else
49
+ puts "\t\n"
50
+ puts "Thank you for your interest! Have a great day, and welcome again in the future!"
51
+ puts "\t\n"
52
+ puts "\t\t\t**************************"
53
+ puts "\t\n"
54
+ end
55
+
56
+ else
57
+ puts "\t\n"
58
+ puts "Would you like to find out more about another landmark? y/n"
59
+ response = gets.chomp.downcase
60
+ if response == "y"
61
+ start
62
+ else
63
+ puts "Thank you for your interest! Have a great day, and welcome again in the future!"
64
+ puts "\t\n"
65
+ puts "\t\t\t**************************"
66
+ puts "\t\n"
67
+ end
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,39 @@
1
+ class Landmarks::Landmark
2
+
3
+ attr_accessor :name, :description, :directions, :url
4
+
5
+ @@all = []
6
+
7
+ def initialize(name=nil, url=nil)
8
+ @name = name
9
+ @url = url
10
+ @@all << self
11
+ end
12
+
13
+ def self.all
14
+ @@all
15
+ end
16
+
17
+ def self.find(number)
18
+ self.all[number - 1]
19
+ end
20
+
21
+ @@scraper = Landmarks::Scraper.new
22
+
23
+ def self.scraper
24
+ @@scraper
25
+ end
26
+
27
+ def name
28
+ @@scraper.scrape_landmark_name(@url)
29
+ end
30
+
31
+ def description
32
+ @@scraper.scrape_landmark_description(@url)
33
+ end
34
+
35
+ def directions
36
+ @@scraper.scrape_landmark_directions(@url)
37
+ end
38
+
39
+ end
@@ -0,0 +1,54 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ class Landmarks::Scraper
6
+
7
+ def get_page
8
+ Nokogiri::HTML(open("http://www.saint-petersburg.com/top-20-attractions/"))
9
+ end
10
+
11
+ def scrape_landmarks_index
12
+ self.get_page.css("h2").each { |el| Landmarks::Landmark.new(el.text, "http://www.saint-petersburg.com"+el.css("a").attr("href").text) }
13
+ end
14
+
15
+
16
+ def print_the_title
17
+ puts self.get_page.css("h1").text
18
+ end
19
+
20
+ def print_landmarks_index
21
+ Landmarks::Landmark.all.each.with_index do |el, index|
22
+ if el.name.include?("\r\n")
23
+ puts "#{index+1}. #{el.name}".gsub("\r\n", "")
24
+ else
25
+ puts "#{index+1}.\t#{el.name}"
26
+ end
27
+ end
28
+ nil
29
+ end
30
+
31
+ def print_landmarks_urls
32
+ Landmarks::Landmark.all.each.with_index { |el, index| puts "#{index+1}.\t#{el.url}" }
33
+ nil
34
+ end
35
+
36
+
37
+ def get_landmark_page(url)
38
+ Nokogiri::HTML(open(url))
39
+ end
40
+
41
+ def scrape_landmark_name(url)
42
+ self.get_landmark_page(url).css("h1").text
43
+ end
44
+
45
+ def scrape_landmark_description(url)
46
+ self.get_landmark_page(url).css("p").text
47
+ end
48
+
49
+ def scrape_landmark_directions(url)
50
+ self.get_landmark_page(url).css(".prop-list").text
51
+ end
52
+
53
+
54
+ end
@@ -0,0 +1,3 @@
1
+ module Landmarks
2
+ VERSION = "0.1.1"
3
+ end
data/spec.md ADDED
@@ -0,0 +1,44 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+
5
+ - [x] Have a CLI for interfacing with the application
6
+
7
+ The CLI interfaces with the application by interacting with the Landmarks::Landmark class, whereas
8
+ all the logic of the interaction between the Landmarks::Landmark class and Landmarks::Scraper class
9
+ is fully encapsulated in the instance and class methods of the Landmarks::Landmark class. First the CLI
10
+ assigns a property of the Landmark class called scraper (which is essentially a newly instantiated
11
+ object of the Scraper class, and we only need one object of this class) to a variable called scraper,
12
+ which then allows us to call an instance method of the Scraper class directly on this variable and to
13
+ scrape and print a numbered list of all our landmarks. After that, inside of the #start method defined
14
+ below, which contains the entire logic of the interaction between the program and the user, the CLI
15
+ is then calling reader instance methods of the Landmark class to display landmarks' properties at the user's
16
+ request. This design actually allows us to adhere to the principle of single responsibility in terms of
17
+ the CLI only interacting with the Landmark class - even the one and only object of the Scraper class is,
18
+ from the point of view of the CLI, just a property of the Landmark class.
19
+
20
+ - [x] Pull data from an external source
21
+
22
+ The first instance method in the Landmarks::Scraper class called #get_page returns the contents of the website
23
+ we are scraping in the form of a set of nested nodes. The following method in the same class called #scrape_landmarks_index
24
+ iterates through the return value of the previous method, instantiates new objects of the Landmarks::Landmark class
25
+ and uses the appropriate CSS selectors to scrape the data, which is then assigned to these objects as their properties.
26
+ It is worth noting that the principle of single responsibility is being adhered to here as well, since each method
27
+ in the Scraper class is on responsible for a single clearly defined action.
28
+
29
+ - [x] Implement both list and detail views
30
+
31
+ The logic of implementation of the list view is contained inside of the method called #call in the CLI class, where
32
+ the #print_the_title method is called on the scraper variable, which, being a property of the Landmark class,
33
+ actually is a newly instantiated object of the Scraper class assigned to the Landmark class as its property
34
+ in the form of a class variable and a reader method. The next method, #print_landmarks_index, is also called on the
35
+ same variable to print the numbered list of the landmarks. Although both #print_the_title and #print_landmarks_index
36
+ methods are instance methods of the Scraper class, from the point of view of the CLI they are called on the variable
37
+ representing a property of the Landmark class.
38
+
39
+ The detailed view of each landmark is implemented through two instance methods of the Landmark class, #description
40
+ (which provides a detailed description of the landmark selected by the user) and, if the user chooses so, #directions
41
+ (which in turn displays some useful information about the landmark, such as directions, business hours, possible
42
+ admission fees etc., if available). The entire logic of this process is encapsulated in the #start method of the CLI
43
+ class. The #start method then calls itself twice (if, after displaying either the description or the details of the
44
+ selected landmark, the user wishes to find out more about another landmark), and is therefore recursive.
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: landmarks-of-st-petersburg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - "'Igor Eskin'"
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-29 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
+ This gem allows to scrape a website of top 20 architectural attractions of St. Petersburg, Russia,
43
+ and by the user's choice display an eloquent description of each individual attraction as well as some useful details (if available),
44
+ such as location, directions, names of other attractions located nearby, business hours and possible admission fee.
45
+ email:
46
+ - "'eskinhd@gmail.com'"
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/landmarks
59
+ - bin/setup
60
+ - config/environment.rb
61
+ - landmarks-of-st-petersburg-0.1.0.gem
62
+ - landmarks.gemspec
63
+ - lib/landmarks.rb
64
+ - lib/landmarks/cli.rb
65
+ - lib/landmarks/landmark.rb
66
+ - lib/landmarks/scraper.rb
67
+ - lib/landmarks/version.rb
68
+ - spec.md
69
+ homepage: https://github.com/igoreskin/landmarks-of-st-petersburg-cli-app
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.6.11
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Top 20 architectural landmarks of St. Petersburg with descriptions and other
93
+ useful information.
94
+ test_files: []